在 longtable 中使用 tabular 时对齐分隔线

在 longtable 中使用 tabular 时对齐分隔线

当我在 longtable 内创建表格时,虽然 longtable 和表格的列宽相同,但单独的行并不对齐。

\documentclass[10pt,twoside]{article} 
\usepackage[a4paper,tmargin=1.75cm, bmargin=0.5cm, lmargin=1.5cm, rmargin=1cm]{geometry}
\usepackage{longtable}
\usepackage{array}
\begin{document}
\begin{longtable}{|p{2cm}|p{4cm}| p{2cm}| }
\hline
X & X & X \\ 
\hline
X & \multicolumn{2}{@{}c@{}}{\begin{tabular}{p{1cm} p{3cm}|p{2cm}|}
A & B & C \\
\end{tabular}} \\
\hline
\end{longtable}
\end{document}

在此处输入图片描述

答案1

两种变体:

\documentclass[10pt,twoside]{article}
\usepackage[a4paper,tmargin=1.75cm, bmargin=0.5cm, lmargin=1.5cm, rmargin=1cm]{geometry}
\usepackage{longtable}
\usepackage{array}
\begin{document}

\begin{longtable}{|p{2cm}|p{4cm}| p{2cm}| }
  \hline
  X & X & X \\
  \hline
  X & \multicolumn{2}{@{}c@{}}{\begin{tabular}{p{1cm} p{3cm}@{\hskip -\tabcolsep}|p{2cm}|}
  A & B & C \\
  \end{tabular}} \\
  \hline
\end{longtable}


\begin{longtable}{|p{2cm}|p{4cm}| p{2cm}| }
  \hline
  X & X & X \\
  \hline
  X & \begin{tabular}{@{}p{1cm} p{3cm}@{}}
  A & B \\
  \end{tabular}
  & C \\
  \hline
\end{longtable}
\end{document} 

在此处输入图片描述

答案2

您需要考虑规则的列分隔和宽度:

\documentclass[10pt,twoside]{article} 
\usepackage[a4paper,tmargin=1.75cm, bmargin=0.5cm, lmargin=1.5cm, rmargin=1cm]{geometry}
\usepackage{longtable}
\usepackage{array}
\begin{document}
\begin{longtable}{|p{2cm}|p{4cm}| p{2cm}| }
\hline
X & X & X \\ 
\hline
X & \multicolumn{2}{@{}c@{}}{\begin{tabular}{
% total 6cm +4\tabcolsep+2\arrayrulewidth
p{\dimexpr1cm-\tabcolsep} p{\dimexpr3cm-\tabcolsep}|p{2cm}|}
A & B & C \\
\end{tabular}} \\
\hline
\end{longtable}
\end{document}

相关内容