使用 \multirow 的不連續線

使用 \multirow 的不連續線

我一直在努力進行表格編輯,因此我開始使用網站在 LaTeX 中產生表格。然而,每當我使用多行和邊框時,事情就會變得有點棘手。我的列上有一條不連續的線。

作為測試,我正在使用這個:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}c|cc@{}}
Test               & a & b \\ \midrule
\multirow{2}{*}{x} & 1 & 2 \\ \cmidrule(l){2-3} 
               & 3 & 4
\end{tabular}
\end{table}

這是結果:

測試台

我將 TexPortable 與 MiKTeX 2.9.6210 和 Texmaker 4.5 一起使用。

答案1

booktabs這與(長度\aboverulesep和)中水平線周圍的填充有關\belowrulesepbooktabs一般情況下不應使用垂直規則(該原則有例外)。解決方法是將它們設為 0,並使用 中的工具將它們替換為在單元頂部和底部添加的或多或少的等效長度makecell

\documentclass{article}
\usepackage{booktabs, multirow, array, makecell, caption}

\begin{document}

\begin{table}[!htb]
\centering
\setlength\aboverulesep{0pt}\setlength\belowrulesep{0pt}
\setcellgapes{3pt}\makegapedcells
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}c|cc@{}}
Test & a & b \\ \midrule
\multirow{2}{*}{x} & 1 & 2 \\ \addlinespace[-0.03em]\cmidrule(l){2-3}
               & 3 & 4
\end{tabular}
\end{table}

\end{document} 

在此輸入影像描述

答案2

如果您希望垂直線與 的水平規則相容booktabs,則應該{NiceTabular}使用nicematrix

\documentclass{article}
\usepackage{booktabs, caption, nicematrix}

\begin{document}

\begin{table}[!htb]
\centering
\caption{My caption}
\label{my-label}
\begin{NiceTabular}{@{}c|cc@{}}[cell-space-limits=3pt]
Test & a & b \\ \midrule
\Block{2-1}{x} & 1 & 2 \\ \cmidrule(l){2-3}
               & 3 & 4
\end{NiceTabular}
\end{table}

\end{document} 

上述程式碼的輸出

相關內容