简体   繁体   English

如何在 Latex 中的列之间绘制垂直线?

[英]How I can draw vertical lines between columns in Latex?

How I can draw vertical lines between column 3 and 4, also between column 2 and 3?如何在第 3 列和第 4 列之间以及第 2 列和第 3 列之间绘制垂直线? I used long table and \multirow and I wrap the text to become inside table but I do not know how I can draw lines between columns?我使用了长表和 \multirow 并将文本包装成表内,但我不知道如何在列之间画线? the wrong result of code is here: https://ibb.co/cQfVs1w代码的错误结果在这里: 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}

Your table is uselessly complicated.你的桌子太复杂了。 You can describe this kind of table in a much simpler and readable way and you do not need multirow.您可以以更简单易读的方式描述这种表,并且不需要多行。 Using multirow is useful in very specific situations, where, for instance, you have a picture, or row description that must span over several rows.使用 multirow 在非常特定的情况下很有用,例如,您有一张图片或必须跨越多行的行描述。

Here is a possible solution.这是一个可能的解决方案。

\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}

在此处输入图像描述 I suppressed the \noalign that creates gaps between the vertical row and the horizontal rules.我抑制了在垂直行和水平规则之间产生间隙的 \noalign 。 Maybe they were intended to fix the incorrect spacing in LaTeX between the rule and the text, but I would suggest you to use instead the booktabs package.也许他们打算修复 LaTeX 中规则和文本之间不正确的间距,但我建议您改用 booktabs package。 It fixes this spacing and provides ways to create tables without vertical columns that are much nicer and readable.它修复了这个间距,并提供了创建没有垂直列的表格的方法,这些表格更加美观和可读。

\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}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM