拉伸桌子,不会断线

拉伸桌子,不会断线

我想将下面的表格拉伸到 15 厘米的宽度,比原始表格更宽。

\documentclass{article}
\usepackage[landscape]{geometry}
\begin{document}

\begin{tabular}{|l|r|r|r|r|r|r|r|r|r|r|r|r|}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & -999.9\\
\hline
\end{tabular}

\end{document}

在此处输入图片描述

我使用如下所示的 tabu 环境。虽然这会生成具有所需宽度的表格,但长单元格现在包含换行符(参见 2015 年 12 月的单元格)。

\documentclass{article}
\usepackage{tabu}
\usepackage[landscape]{geometry}
\begin{document}

\begin{tabu} to 15cm {|X[l]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & -999.9\\
\hline
\end{tabu}

\end{document}

在此处输入图片描述

如何拉伸表格以填充可用宽度而不将单元格内容分成两行?

答案1

先说一句:如果使用 10pt(或更大)的字体大小,那么如果表格宽度只有 15 厘米,则表格内容将无法容纳。我建议您增加其宽度,比如说\textwidth

我建议您使用tabularx环境而不是基本环境,并对第 2 列至第 13 列tabular使用修改后的(即左边不规则的)版本的列类型。X

另外,您可能还想考虑让表格看起来更“开放”,方法是省略所有垂直线,并减少水平线的数量,但间隔要适当。以下屏幕截图中的第二个表格展示了这种开放的外观,这是借助该booktabs包的线条绘制宏实现的。

在此处输入图片描述

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{tabularx,booktabs}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\setlength\parindent{0pt} % just for this example

With lots of horizontal and vertical lines:

\smallskip
\begin{tabularx}{\textwidth}{|l|*{12}{R|}}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & $-999.9$\\
\hline
\end{tabularx}

\bigskip\bigskip
With \emph{no} vertical lines and fewer, but well-spaced, horizontal lines:

\smallskip
\begin{tabularx}{\textwidth}{l*{12}{R}}
\toprule
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\midrule
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & $-999.9$\\
\bottomrule
\end{tabularx}

\end{document}

相关内容