表格中漂亮的垂直线条

表格中漂亮的垂直线条

请问如何在表格中创建更美观的垂直线?它们应该从第二行延伸到底线,且不重叠和留空。

\documentclass[12pt,a4paper,twoside,openright]{report}
\usepackage{multirow}

\begin{document}
\begin{table}[h!]
\centering
\small
\begin{center}
\begin{tabular}{c|cc|cc|cc}
\hline\hline
A                   &\multicolumn{2}{c}{B}     &\multicolumn{2}{c}{C}  &\multicolumn{2}{c}{D}    \\
                                   
\hline
\multirow{2}{*}{A} &\multirow{2}{*}{B} &\multirow{2}{*} {C} &\multirow{2}{*}{D} &\multirow{2}{*}{E} &\multirow{2}{*}{F} &\multirow{2}{*}{G} \\
&&&&&&\\[-5pt]

\hline
\end{tabular}
\end{center}
\end{table}

\end{document}

在此处输入图片描述

答案1

(对我来说)不清楚你喜欢在哪里画垂直线。对于水平线,有很多选择:

在此处输入图片描述

使用这个tabularray包,所有显示的表格都很容易编写。但是,除了显示示例外,进行其他组合也很简单...

\documentclass[12pt,a4paper,twoside,openright]{report}
\usepackage{tabularray}

\begin{document}
    \begin{table}[ht!]
    \centering
\begin{tblr}{hlines,
             colspec={c|cc|cc|cc},
             }
    \hline
A   & \SetCell[c=2]{c}  B 
        &   &  \SetCell[c=2]{c} C 
                &   &  \SetCell[c=2]{c} D 
                        &       \\
A   & B & C & D & E & F & G     \\
A   & B & C & D & E & F & G     \\
\end{tblr}
    \end{table}
    
or
    \begin{table}[ht!]
    \centering
\begin{tblr}{hline{1,Z} = 1pt, hline{2-Y}=0.2pt,
             colspec={c|cc|cc|cc},
             }
A   & \SetCell[c=2]{c}  B
        &   &  \SetCell[c=2]{c} C
                &   &  \SetCell[c=2]{c} D
                        &       \\
A   & B & C & D & E & F & G     \\
A   & B & C & D & E & F & G     \\
\end{tblr}
    \end{table}
    
or
    \begin{table}[ht!]
    \centering
\begin{tblr}{hline{1,Z} = 1pt, hline{2}=0.6pt, hline{3-Y}=0.2pt,
             colspec={c|cc|cc|cc},
             }
A   & \SetCell[c=2]{c}  B
        &   &  \SetCell[c=2]{c} C
                &   &  \SetCell[c=2]{c} D
                        &       \\
A   & B & C & D & E & F & G     \\
A   & B & C & D & E & F & G     \\
\end{tblr}
    \end{table}

or
    \begin{table}[ht!]
    \centering
\begin{tblr}{hline{1,Z} = 1pt, hline{2}=0.6pt, hline{3-Y}=0.2pt,
             vlines,
             cells={c},
             }
A   & \SetCell[c=2]{c}  B
        &   &  \SetCell[c=2]{c} C
                &   &  \SetCell[c=2]{c} D
                        &       \\
A   & B & C & D & E & F & G     \\
A   & B & C & D & E & F & G     \\
\end{tblr}
    \end{table}
\end{document}

答案2

请尝试戒掉表格中的垂直线。相信我,垂直线是不必要的,而且大多数表格实际上没有垂直线看起来会好得多。并且,一定要使用书签软件包 -- 例如\toprule\midrule\cmidrule\bottomrule-- 代替\hline和 编程补丁,例如\noalign{\smallskip}

在此处输入图片描述

\documentclass[12pt,a4paper,twoside,openright]{report}
\usepackage{multirow}
\usepackage{booktabs} % <-- new
\begin{document}

\begin{table}[h!]
\centering

\begin{tabular}{c|cc|cc|cc}
\multicolumn{7}{c}{with vertical lines}\\
\hline\hline
A &\multicolumn{2}{c}{B} &\multicolumn{2}{c}{C} &\multicolumn{2}{c}{D} \\                           
\hline
\multirow{2}{*}{A} &\multirow{2}{*}{B} &\multirow{2}{*} {C} &\multirow{2}{*}{D} &\multirow{2}{*}{E} &\multirow{2}{*}{F} &\multirow{2}{*}{G} \\
&&&&&&\\[-5pt]
\hline
\end{tabular}

\bigskip\bigskip
\begin{tabular}{@{} l *{6}{c} @{}}
\multicolumn{7}{c}{without vertical lines}\\
\toprule
A &\multicolumn{2}{c}{B} &\multicolumn{2}{c}{C} &\multicolumn{2}{c@{}}{D} \\                           
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7}
A & B & C & D & E & F & G \\
\midrule
\dots & \dots & \dots & \dots & \dots & \dots & \dots \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

相关内容