这个过满和欠满表该如何正确写出?

这个过满和欠满表该如何正确写出?

我有一张表,其中的单词太长呋塞米到达。引起overfull警告,以及引起underfull警告的事情

\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{| p{.15\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | p{.06\linewidth} | }   
\hline
\textit{Sinus}           & 18 & 0 & 0 & 0 
        & 0 & 0 & 306 
        & 0 & 18 \\ \hline
\textit{Furosemide arr.} & 5 & 0 & 0 & 0 
        & 0 & 0 & 20 
        & 0 & 5 \\ \hline
\end{tabular}
\end{table}

\end{document}

输出

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./test.tables.tex
LaTeX2e <2016/03/31> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(./test.tables.aux)
Underfull \hbox (badness 10000) in paragraph at lines 11--11
[]\OT1/cmr/m/it/10 Furosemide

Overfull \hbox (13.04031pt too wide) in paragraph at lines 6--15
[][] 
[1{/home/masi/.texlive2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./test.tables.aux) )
(see the transcript file for additional information)</usr/local/texlive/2016/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/local/texlive/2016/texm
f-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb>
Output written on test.tables.pdf (1 page, 21354 bytes).
Transcript written on test.tables.log.

答案1

普通的桌子有什么问题?

\documentclass{article}

\begin{document}

\begin{table}

\begin{tabular}{|l|*{9}{r|}}
\hline
\textit{Sinus}           & 18 & 0 & 0 & 0 & 0 & 0 & 306 & 0 & 18 \\ \hline
\textit{Furosemide arr.} & 5 & 0 & 0 & 0  & 0 & 0 & 20 & 0 & 5 \\ \hline
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

如果要确保所有数字单元格具有相同的宽度,请使用siunitx

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\begin{table}

\begin{tabular}{|l|*{9}{S[table-format=3.0]|}}
\hline
\textit{Sinus}           & 18 & 0 & 0 & 0 & 0 & 0 & 306 & 0 & 18 \\ \hline
\textit{Furosemide arr.} & 5 & 0 & 0 & 0  & 0 & 0 & 20 & 0 & 5 \\ \hline
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

答案2

您指定的表格太宽(参见第一个表格),但这里没有理由使用 p 列,您想要像第二个表格一样的十进制对齐数字。

在此处输入图片描述

\documentclass{article}
\usepackage{dcolumn}

\begin{document}
\newlength\mylen
\begin{table}
\centering

\mylen=\dimexpr\linewidth-20\tabcolsep-11\arrayrulewidth\relax
\begin{tabular}{@{}| p{.37\mylen}| *{9}{ p{.07\mylen} |}@{}}
\hline
\textit{Sinus}           & 18 & 0 & 0 & 0 
        & 0 & 0 & 306 
        & 0 & 18 \\ \hline
\textit{Furosemide arr.} & 5 & 0 & 0 & 0 
        & 0 & 0 & 20 
        & 0 & 5 \\ \hline
\end{tabular}

\bigskip

\tabcolsep=5pt
\begin{tabular}{@{}|l| *{9}{D..{3.0}|}@{}}
\hline
\textit{Sinus}           & 18 & 0 & 0 & 0 
        & 0 & 0 & 306 
        & 0 & 18 \\ \hline
\textit{Furosemide arr.} & 5 & 0 & 0 & 0 
        & 0 & 0 & 20 
        & 0 & 5 \\ \hline
\end{tabular}

\end{table}

\end{document}

答案3

我会测量第 2-10 列中最宽的元素,然后将这些列设置为该宽度(促进某种形式的水平一致性)。此外,使用tabularx设置剩余(第一)列以填充完整\textwidth

在此处输入图片描述

\documentclass{article}

\usepackage{tabularx}
\newlength{\templength}
\begin{document}

\begin{table}
  \settowidth{\templength}{306}% Widest element in columns 2-10
  \begin{tabularx}{\textwidth}{ | X | *{9}{>{\raggedleft\arraybackslash}p{\templength} |} } 
    \hline
    \textit{Sinus} & 18 & 0 & 0 & 0 
                   & 0 & 0 & 306 
                   & 0 & 18 \\
    \hline
    \textit{Furosemide arr.} & 5 & 0 & 0 & 0 
                   & 0 & 0 & 20 
                   & 0 & 5 \\
    \hline
  \end{tabularx}
\end{table}

\end{document}

我也会用booktabs以获得更具吸引力的视觉效果。您将获得每个垂直规则的大量\tabcolseps,而这些 s 并不是真正需要的。

答案4

使用tabularx相等宽度的单元格很容易确定:

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\begin{table}
  \begin{tabularx}{\textwidth}{ | l | *{9}{>{\raggedleft\arraybackslash}X |} }
    \hline
    \textit{Sinus} & 18 & 0 & 0 & 0
                   & 0 & 0 & 306
                   & 0 & 18 \\
    \hline
    \textit{Furosemide arr.} & 5 & 0 & 0 & 0
                   & 0 & 0 & 20
                   & 0 & 5 \\
    \hline
  \end{tabularx}
\end{table}
\end{document}

相关内容