我想在表格中居中绘制内部垂直线。
示例代码:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\multirow{2}{*}{R} & \multicolumn{2}{c|}{No. Jobs Completed/Submitted} \\ \cline{2-3}
& C1 & C2 \\ \hline
r1 & a & b \\ \hline
r2 & a & b \\ \hline
\end{tabular}
\end{document}
其输出:
想要的输出:如果可能的话,我希望 C1 和 C2 列被均等分割。
---------------------------------
|R |No. Jobs Completed/Submitted|
|r1| C1 | C2 |
|-------------------------------|
|r2| a | b |
--------------------------------
答案1
您可以使用包w
中的 -column 类型array
:
\documentclass{article}
\usepackage{multirow,array}
\begin{document}
\setlength{\extrarowheight}{1pt}
\begin{tabular}{|c|w{c}{3cm}|w{c}{3cm}|}
\hline
\multirow{2}{*}{R} & \multicolumn{2}{c|}{No. Jobs Completed/Submitted} \\ \cline{2-3}
& C1 & C2 \\ \hline
r1 & a & b \\ \hline
r2 & a & b \\ \hline
\end{tabular}
\end{document}
答案2
使用该tabularray
包,您可以使用hspan=even
选项来均匀分布各列:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
colspec={|c|c|c|},
hspan=even
}
\hline
\SetCell[r=2]{} R & \SetCell[c=2]{} No. Jobs Completed/Submitted & \\ \cline{2-3}
& C1 & C2 \\ \hline
r1 & a & b \\ \hline
r2 & a & b \\ \hline
\end{tblr}
\end{document}
答案3
与 nicematrix
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}[width=0.6\linewidth]{cX[c]X[c]}[hvlines,cell-space-limits=2pt]
\Block{2-1}{R} & \Block{1-2}{No. Jobs Completed/Submitted} & \\
& C1 & C2 \\
r1 & a & b \\
r2 & a & b \\
\end{NiceTabular}
\vspace{\baselineskip}
or
\vspace{\baselineskip}
\begin{NiceTabular}{c W{c}{3cm} W{c}{3cm}}[hvlines,cell-space-limits=2pt]
\Block{2-1}{R} & \Block{1-2}{No. Jobs Completed/Submitted} & \\
& C1 & C2 \\
r1 & a & b \\
r2 & a & b \\
\end{NiceTabular}
\end{document}
答案4
精神上与斯蒂芬的回答,但使用表格标题的自然宽度进行测量:
\documentclass{article}
\usepackage{multirow, array}
\newlength\mylength
\begin{document}
\settowidth\mylength{No. Jobs Completed/Submitted}
\mylength=.5\dimexpr\mylength-\arrayrulewidth-2\tabcolsep\relax
\begin{tabular}{|c|*2{w{c}{\mylength}|}}
\hline
\multirow{2}{*}{R} & \multicolumn{2}{c|}{No. Jobs Completed/Submitted} \\ \cline{2-3}
& C1 & C2 \\ \hline
r1 & a & b \\ \hline
r2 & a & b \\ \hline
\end{tabular}
\end{document}
我认为,通过删除所有垂直规则并使用booktabs
水平规则,可以美化您的表格版本:
\documentclass{article}
\usepackage{multirow, booktabs, array}
\newlength\mylength
\begin{document}
\settowidth\mylength{No. Jobs Completed/Submitted}
\mylength=.5\dimexpr\mylength-2\tabcolsep\relax
\begin{tabular}{c*2{w{c}{\mylength}}}
\toprule
\multirow{2}{*}{R} & \multicolumn{2}{c}{No. Jobs Completed/Submitted} \\
& C1 & C2 \\
\midrule
r1 & a & b \\
r2 & a & b \\
\bottomrule
\end{tabular}
\end{document}