使用表格时值未对齐

使用表格时值未对齐

我无法正确显示下表:

\documentclass[12pt]{report}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{float,lscape}
\usepackage{longtable}
\usepackage{tabularx}
\makeatletter
\def\hlinewd#1{%
  \noalign{\ifnum0=`}\fi\hrule \@height #1 \futurelet
   \reserved@a\@xhline}
\makeatother
\usepackage{multirow}
\usepackage{bigstrut}

\begin{table}[htbp]
  \centering
  \caption{Yearly membership growth for different time periods}
  \scriptsize
    \begin{tabulary}{\textwidth}{LLLLLLLLLLLLLLLLL}
    \hlinewd{1.25pt}
    \textbf{a. Time period 1886 - 1892:} & \textbf{} & \textbf{} &       &       &       &       &       &       &       &       &       &       &       &       &       &  \bigstrut\\
\cline{1-8}    \multicolumn{1}{C}{86} & \multicolumn{1}{C}{87} & \multicolumn{1}{C}{88} & \multicolumn{1}{C}{89} & \multicolumn{1}{C}{90} & \multicolumn{1}{C}{91} & \multicolumn{1}{C}{92} & \multicolumn{1}{C}{AVG} &       &       &       &       &       &       &       &       &  \bigstrut\\
\cline{1-8}    \multicolumn{1}{C}{485} & \multicolumn{1}{C}{229} & \multicolumn{1}{C}{372} & \multicolumn{1}{C}{401} & \multicolumn{1}{C}{488} & \multicolumn{1}{C}{261} & \multicolumn{1}{C}{444} & \multicolumn{1}{C}{383} &       &       &       &       &       &       &       &       &  \bigstrut\\
\cline{1-8}          &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &  \bigstrut[t]\\
    \textbf{b. Time period 1911 - 1926:} & \textbf{} & \textbf{} &       &       &       &       &       &       &       &       &       &       &       &       &       &  \bigstrut[b]\\
    \hline
    \multicolumn{1}{C}{11} & \multicolumn{1}{C}{12} & \multicolumn{1}{C}{13} & \multicolumn{1}{C}{14} & \multicolumn{1}{C}{15} & \multicolumn{1}{C}{16} & \multicolumn{1}{C}{17} & \multicolumn{1}{C}{18} & \multicolumn{1}{C}{19} & \multicolumn{1}{C}{20} & \multicolumn{1}{C}{21} & \multicolumn{1}{C}{22} & \multicolumn{1}{C}{23} & \multicolumn{1}{C}{24} & \multicolumn{1}{C}{25} & \multicolumn{1}{C}{26} & \multicolumn{1}{C}{AVG} \bigstrut\\
    \hline
    \multicolumn{1}{C}{338} & \multicolumn{1}{C}{929} & \multicolumn{1}{C}{528} & \multicolumn{1}{C}{1'426} & \multicolumn{1}{C}{-301} & \multicolumn{1}{C}{117} & \multicolumn{1}{C}{375} & \multicolumn{1}{C}{293} & \multicolumn{1}{C}{652} & \multicolumn{1}{C}{2'671} & \multicolumn{1}{C}{1'370} & \multicolumn{1}{C}{544} & \multicolumn{1}{C}{786} & \multicolumn{1}{C}{479} & \multicolumn{1}{C}{440} & \multicolumn{1}{C}{800} & \multicolumn{1}{C}{715} \bigstrut\\
    \hlinewd{1.25pt}
    \end{tabulary}%
  \label{tab:addlabel}%
\end{table}%

结果如下图所示:

桌子

虽然表格的定位很好,但我不明白为什么 latex 在从第一组数字开始后,将其余的数字全部放在右侧。右侧的数字(87、88、89、...)也应该向左对齐。我该如何管理这个表格?

一如既往,非常感谢您的帮助!

答案1

您应该使用tabular\multicolumn{17}{l}{...}来表示跨列的条目:

\documentclass[12pt]{report}
\usepackage{booktabs}
\usepackage{caption}

\begin{document}
\begin{table}[htbp]
\centering
\caption{Yearly membership growth for different time periods}
\label{tab:addlabel}

\scriptsize

\addtolength{\tabcolsep}{-1.8pt}
\begin{tabular}{*{17}{c}}
\toprule
\multicolumn{17}{l}{\textbf{a. Time period 1886--1892}} \\

\cmidrule[\lightrulewidth]{1-8}

86 & 87 & 88 & 89 & 90 & 91 & 92 & AVG & & & & & & & & & \\

\cmidrule[\lightrulewidth]{1-8}

485 & 229 & 372 & 401 & 488 & 261 & 444 & 383 & & & & & & & & & \\

\cmidrule[\lightrulewidth]{1-8}

\multicolumn{17}{l}{\textbf{b. Time period 1911--1926}} \\

\midrule

11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & AVG \\

\midrule

338 & 929 & 528 & 1426 & $-301$ & 117 & 375 & 293 & 652 & 2671 & 1370 & 544 & 786 &
  479 & 440 & 800 & 715 \\
\bottomrule
\end{tabular}

\end{table}

\begin{table}[htbp]
\centering
\caption{Yearly membership growth for different time periods}
\label{tab:addlabel-double}

\footnotesize

\addtolength{\tabcolsep}{-3.1pt}
\begin{tabular}{*{17}{c}}
\toprule
\multicolumn{17}{l}{\textbf{a. Time period 1886--1892}} \\

\cmidrule[\lightrulewidth]{1-8}

86 & 87 & 88 & 89 & 90 & 91 & 92 & AVG & & & & & & & & & \\

\cmidrule[\lightrulewidth]{1-8}

485 & 229 & 372 & 401 & 488 & 261 & 444 & 383 & & & & & & & & & \\

\cmidrule[\lightrulewidth]{1-8}

\multicolumn{17}{l}{\textbf{b. Time period 1911--1926}} \\

\midrule

11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 & AVG \\

\midrule

338 & 929 & 528 & 1426 & $-301$ & 117 & 375 & 293 & 652 & 2671 & 1370 & 544 & 786 &
  479 & 440 & 800 & 715 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

无需\bigstrut更严格的规则或复杂的代码。

我提供了两个版本的表格,第二个使用\footnotesize

我如何计算-3.1pt修复?

我运行文档时没有\addtolength结果发现,在第二种情况下,超出了 104.69522pt。由于 104.69522/34 约为 3.079,因此我将其四舍五入。

第一个版本也类似。

在此处输入图片描述

如果你想要第二个标题上方有一些垂直空间,请使用\addlinespace

...

485 & 229 & 372 & 401 & 488 & 261 & 444 & 383 & & & & & & & & & \\

\cmidrule[\lightrulewidth]{1-8}

\addlinespace[\medskipamount]

\multicolumn{17}{l}{\textbf{b. Time period 1911--1926}} \\

\midrule

...

在此处输入图片描述

答案2

后面的列都是左对齐的,但是第一列非常宽,因为

 \textbf{a. Time period 1886 - 1892:} 

这会强制改变列的宽度。也许你打算使用\multicolumn它来跨越所有列,而不是强制第一列变宽?

tabulary(和tabularx)不适合这种桌子,它们通过改变换行每列指定宽度。由于您的列主要由数值数据组成,因此换行并不重要,因此您最好使用标准的tabular

相关内容