latex 三线表 与调整表格与上下文的间距

最近遇到要用Latex画三线表,时间紧不能去细细了解每句功能,记录一下后面参考别人画的表格,以后可以直接移植。三线表只是实现最普通的功能,想要的风格是两边没有竖线,而且中间的表格需要占两行,由于用到了\multirow行合并指令,我添加了两个宏包\usepackage{multirow},\usepackage{booktabs}。
latex 三线表 与调整表格与上下文的间距_第1张图片
这个表由于不对称看起来有点别扭,不过作为以后别的表格改进的基础版也是可以的。(3,8)和(4,5,9,10)之间的竖线调了挺久,因为不是贯穿到底的直线,注意\vline指令的使用。下面粘出具体的代码。

\renewcommand{\multirowsetup}{\centering}
\begin{center}
\begin{tabular}{ll|llll}
\cline{2-3}
\multirow{2}{2cm}{}
       & \multirow{2}{5cm}{1}
       & \multirow{2}{6cm}{2} \\&\\
\hline
\multirow{2}{2cm}{3}
        & \vline \multirow{2}{5cm}{4 \\5}
        & \multirow{2}{6cm}{6 \\ 7}
        & \\ &\vline\\
\hline
\multirow{2}{2cm}{8}
        & \vline \multirow{2}{5cm}{9 \\ 10}
        & \multirow{2}{6cm}{11 \\ 12}
        & \\ & \vline \\
\hline
\end{tabular}
\end{center}

后面还是用回了最普通的形式,很多论文都是采用的这样的表格,简单大方:latex 三线表 与调整表格与上下文的间距_第2张图片

\renewcommand{\multirowsetup}{\centering}
\begin{center}
\begin{tabular}{l|l|llll}
\hline
\multirow{2}{2cm}{}
       & \multirow{2}{5cm}{1}
       & \multirow{2}{6cm}{2} \\&\\
\hline
\multirow{2}{2cm}{3}
        &  \multirow{2}{5cm}{4 \\5}
        & \multirow{2}{6cm}{6 \\ 7}
        & \\ &\\
\hline
\multirow{2}{2cm}{8}
        &  \multirow{2}{5cm}{9 \\ 10}
        & \multirow{2}{6cm}{11 \\ 12}
        & \\ & \\
\hline
\end{tabular}
\end{center}

表格完成后发现与上下文间距太大了,用\setlength{\abovecaptionskip}{-0.15cm}、\setlength{\belowcaptionskip}{-1cm}这两个指令的效果不太好,调整表格标题与上文间距还行,但是与下文的间距就完全不起作用了。后面发现用\vspace{-0.8cm}这个指令效果很好,要调整与下文间距就再用一次就可以了。下面粘出最终的成果。
latex 三线表 与调整表格与上下文的间距_第3张图片

This is a demo.

\renewcommand{\multirowsetup}{\centering}
\vspace{-0.8cm}
\begin{table}
\caption{The caption.}
\begin{center}
\begin{tabular}{l|l|llll}
\toprule
\multirow{2}{2cm}{}
       & \multirow{2}{5cm}{1}
       & \multirow{2}{6cm}{2} \\&\\
\midrule
\multirow{2}{2cm}{3}
        &  \multirow{2}{5cm}{4 \\5}
        & \multirow{2}{6cm}{6 \\ 7}
        & \\ &\\
\hline
\multirow{2}{2cm}{8}
        &  \multirow{2}{5cm}{9 \\ 10}
        & \multirow{2}{6cm}{11 \\ 12}
        & \\ & \\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\vspace{-0.8cm}
This is a demo.

你可能感兴趣的:(Latex)