表格中 \multicolumn 的虚假前导水平空格

表格中 \multicolumn 的虚假前导水平空格

当我\multicolumn在 a tabular(或tabularx)中使用 a 时,似乎在列开头添加了额外的水平间距,尽管l指定了 eft 对齐\multicolumn。此表中的最后一行显示了此问题:

enter image description here

为什么那里会有间距?我该如何消除它?

代码:

\documentclass{article}
\usepackage{tabularx}
\usepackage[showframe,textwidth=7.0cm]{geometry}

\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{}X l l@{}}
Sub Item 1 & 3,000 \\
Sub Item 2 & 4,000 \\
Total      &       & 7,000 \\
\multicolumn{3}{l}{$\leftarrow$ Why is there space to the left of this?} \\
\end{tabularx}
\bigskip
\par\noindent
\begin{tabular}{@{}l l l@{}}
Sub Item 1 & 3,000 \\
Sub Item 2 & 4,000 \\
Total      &       & 7,000 \\
\multicolumn{3}{l}{$\leftarrow$ Why is there space to the left of this?} \\
\end{tabular}
\end{document}

答案1

这是由\arraycolsep参数决定的。如果你的问题是“如何避免这种跳过”,解决方案很简单:

\documentclass{article}
\usepackage{tabularx}
\usepackage[showframe,textwidth=7.0cm]{geometry}

\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{}X l l@{}}
Sub Item 1 & 3,000 \\
Sub Item 2 & 4,000 \\
Total      &       & 7,000 \\
%\multicolumn{3}{l}{$\leftarrow$ Why is there space to the left of this?} \\
\multicolumn{3}{@{}l}{$\leftarrow$ Why is there space to the left of this?} \\
\end{tabularx}
\end{document}

相关内容