为什么我的表格比其列宽的总和更宽?

为什么我的表格比其列宽的总和更宽?

创建具有固定宽度列的表格很简单,例如

\begin{tabular}{|p{95mm}|p{95mm}|} \hline
a & b \\ \hline
b & b \\ \hline
c & b \\ \hline
\end{tabular} 

然而,所有表格的宽度不会是190mm. (文本宽度设置为190mm)。

换句话说,每列的宽度都比表格前言中所写的要大。

您与这种现象有关系吗?

答案1

\tabcolsep列条目的两边都有填充,另外(如果您使用array包裹) 垂直规则的宽度(\arrayrulewidth)。array实现不同的方式处理内部的垂直规则tabular。以下内容摘自array.dtx- 节省内存的策略:

% \begin{macro}{\@arrayrule}
%    There is only one incompatibility with the original definition:
%    the definition of =\@arrayrule=. In the original a line without
%    width\footnote{So the space between \texttt{cc} and \texttt{c|c}
%    is equal.}  is created by multiple insertions of 
% =\hskip .5\arrayrulewidth=.  
%    We only insert a vertical line into the
%    preamble.  This is done to prevent problems with \TeX's main
%    memory when generating tables with many vertical lines in them
%    (especially in the case of \textsf{floats}).
%    \begin{macrocode}

没有 array已加载,使用

\begin{tabular}{|p{\dimexpr 95mm-2\tabcolsep}|%
                 p{\dimexpr 95mm-2\tabcolsep}|} \hline
  a & b \\ \hline
  b & b \\ \hline
  c & b \\ \hline
\end{tabular}

array加载后,即可使用

\begin{tabular}{|p{\dimexpr 95mm-2\tabcolsep-1.5\arrayrulewidth}|%
                 p{\dimexpr 95mm-2\tabcolsep-1.5\arrayrulewidth}|} \hline
  a & b \\ \hline
  b & b \\ \hline
  c & b \\ \hline
\end{tabular}

应该\tabcolsep从每一列中删除 2 个(两边的填充),以及每列宽度的 1.5 倍\arrayrulewidth(整个 共计 3 个tabular)。

对于列数较多的表格,结构相同,只是删除的 s 数量不同\arrayrulewidth。虽然每列仍有 2 个\tabcolseps,但您将从每列中删除分数规则/列\arrayrulewidth。因此,对于 8 列和 9 条规则,删除 9/8 或1.125\arrayrulewidth

答案2

这是因为默认添加了一些空间来将各列彼此分隔开(通过\tabcolsep)。参见http://chenfuture.wordpress.com/2007/09/20/latex-tabular-more/

相关内容