【问题标题】:How I can draw vertical lines between columns in Latex?如何在 Latex 中的列之间绘制垂直线?
【发布时间】:2019-10-14 18:25:47
【问题描述】:
如何在第 3 列和第 4 列之间以及第 2 列和第 3 列之间绘制垂直线?
我使用了长表和 \multirow 并将文本包装成表内,但我不知道如何在列之间画线?
代码的错误结果在这里:
https://ibb.co/cQfVs1w
\begin{longtable}[H] {|p{2cm}|p{2.8cm}|p{2.8cm}|p{2.8cm}|}
% table caption is above the table
\caption{xxx}
\label{tab:2} % Give a unique label
% For LaTeX tables use
%\begin{tabular}{|p{2cm}|p{2.8cm}|p{2.8cm}|p{2.8cm}|}
\\
\hline\noalign{\smallskip}
Reference & Description & Advantages & Limitations \\
\noalign{\smallskip}\hline\noalign{\smallskip}
xx & xx & {\multirow{3}{*}{\parbox{2.8cm} {1.xxx\\
2. xxxx\\
3. xxx \\
4. xxx \\
5. xxx\\
6. xxxx\\
7. xxxx\\
}}}
& {\multirow{3}{*}{\parbox{2.8cm}{ 1. xxx\\
2. xxx\\
3. xxx\\
4. xxx\\
}}}\\
xx [18] & xxx & & \\
xx [6] & xxx & & \\
\\
\\
\\
\\
\noalign{\smallskip}\hline
%\end{tabular}
\end{longtable}
【问题讨论】:
标签:
latex
multirow
longtable
【解决方案1】:
你的桌子太复杂了。您可以以更简单易读的方式描述这种表,并且不需要多行。使用 multirow 在非常特殊的情况下很有用,例如,您的图片或行描述必须跨越多行。
这是一个可能的解决方案。
\documentclass{article}
\usepackage{longtable}
%\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\begin{longtable}[H] {|p{2cm}|p{2.8cm}|p{2.8cm}|p{2.8cm}|}
% table caption is above the table
\caption{xxx}
\label{tab:2} % Give a unique label
% For LaTeX tables use
%\begin{tabular}{|p{2cm}|p{2.8cm}|p{2.8cm}|p{2.8cm}|}
\\\hline %%%% \noalign{\smallskip}
Reference & Description & Advantages & Limitations \\
%%%%%%%% \noalign{\smallskip}\hline\noalign{\smallskip}
\hline
xx & xx & 1. xxx & 1. xxx\\
xx[18] & xxx & 2. xxxx & 2. xxx\\
xx [6] & xxx & 3. xxx & 3. xxx\\
& & 4. xxx & 4. xxx\\
& & 5. xxx & \\
& & 6. xxxx & \\
& & 7. xxxx & \\
\hline
%\end{tabular}
\end{longtable}
\end{document}
我抑制了在垂直行和水平规则之间产生间隙的 \noalign 。也许他们打算修复 LaTeX 中规则和文本之间不正确的间距,但我建议您改用 booktabs 包。它修复了这个间距,并提供了创建没有垂直列的表格的方法,这些表格更加美观和可读。
\begin{longtable}[H] {p{2cm}p{2.8cm}p{2.8cm}p{2.8cm}}
% table caption is above the table
\caption{xxx}
\label{tab:2} % Give a unique label
\\\toprule
Reference & Description & Advantages & Limitations \\
\midrule
xx & xx & 1.xxx & 1. xxx\\
xx[18] & xxx & 2. xxxx & 2. xxx\\
xx [6] & xxx & 3. xxx & 3. xxx\\
& & 4. xxx & 4. xxx\\
& & 5. xxx & \\
& & 6. xxxx & \\
& & 7. xxxx & \\
\bottomrule
\end{longtable}