使用 tabularx 时 \hbox 溢出

使用 tabularx 时 \hbox 溢出

我发现了很多有关Overfull \hbox警告的相关问题,tabularx但到目前为止都没有帮助我。

这是重现警告的最小代码(当然,真正的表格没有那么丑陋):

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}


\begin{document}

\begin{tabularx}{0.95\textwidth}{X S[table-format=2.0]}
\toprule
Text & 5 \\ \midrule
A & 51\% \\
B & 39\% \\
C & 30\% \\
D & 25\% \\
E & 20\% \\
F & 17\% \\
G & 8\% \\
H & 6\% \\
I & 3\% \\
\bottomrule
\end{tabularx}

\end{document}

这是输出

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./main.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size11.clo))
(/usr/local/texlive/2014/texmf-dist/tex/latex/booktabs/booktabs.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/tools/tabularx.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/tools/array.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/siunitx/siunitx.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/expl3-code.tex
(/usr/local/texlive/2014/texmf-dist/tex/latex/etex-pkg/etex.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/l3unicode-data.def)
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2014/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/translator.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/translator-lang
uage-mappings.tex))) (./main.aux)
(/usr/local/texlive/2014/texmf-dist/tex/latex/beamer/translator/dicts/translato
r-basic-dictionary/translator-basic-dictionary-English.dict)
(/usr/local/texlive/2014/texmf-dist/tex/latex/siunitx/siunitx-abbreviations.cfg
)
Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 

Overfull \hbox (9.12502pt too wide) detected at line 25
\OT1/cmr/m/n/10.95 % 
[1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./main.aux) )
(see the transcript file for additional information)</usr/local/texlive/2014/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on main.pdf (1 page, 15096 bytes).
SyncTeX written on main.synctex.gz.
Transcript written on main.log.

25号线是\end{tabularx}


我尝试过的:

  • 打开环境\noindent前使用;tabularx
  • 减少表格的宽度;
  • 使用\end{tabularx}{\parfillskip=0pt\par}
  • 更改 中的列{@{}X@{}S[table-format=2.0]@{}}

任何帮助,将不胜感激。

答案1

您需要为%( )添加一些空间S[table-format=2.0],这样列的宽度才足以容纳 所附加的数字%,从而导致框溢出。请尝试:

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}


\begin{document}

\begin{tabularx}{0.95\textwidth}{X S[table-format=2.0,table-space-text-post={\%}]}
\toprule
Text & 5 \\ \midrule
A & 51\% \\
B & 39\% \\
C & 30\% \\
D & 25\% \\
E & 20\% \\
F & 17\% \\
G & 8\% \\
H & 6\% \\
I & 3\% \\
\bottomrule
\end{tabularx}

\end{document}

答案2

另一种解决方案是自动排版%

\documentclass[a4paper,11pt]{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}

\setlength{\extrarowheight}{3pt}

\begin{document}

 \begin{tabularx}{0.95\textwidth}{X S[table-format=2.0]<{\,\%}}
  \toprule
  Text & \multicolumn{1}{c}{5} \\ \midrule
  A & 51 \\
  B & 39 \\
  C & 30 \\
  D & 25 \\
  E & 20 \\
  F & 17 \\
  G & 8 \\
  H & 6 \\
  I & 3 \\
  \bottomrule
\end{tabularx}

\end{document} 

在此处输入图片描述

相关内容