3

I have a problem with properly displaying following table:

\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}%

The result looks like in the following picture:

Table

While the positioning of the table is fine, I don't understand why latex, after starting with the first set of numbers, puts the rest all to the right. The numbers on the right (87, 88, 89, ....) should be aligned to the left too. How can I manage this for this table?

Many thanks for your help, as always!

  • the posted code generates multiple errors (not least missing \begin{document} but still generates errors if that is added. Please post code that generates the image shown – David Carlisle Dec 16 '14 at 22:28
  • the numbers 87,... are left aligned in their column, so I don't understand your comment that they are "to the right" ?? – David Carlisle Dec 16 '14 at 22:30
4

You should use tabular and \multicolumn{17}{l}{...} for the entries spanning columns:

\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}

No need for \bigstrut or complicated code for heavier rules.

I provided two versions of the table, the second uses \footnotesize.

How did I compute the -3.1pt fix?

I ran the document without \addtolength and got, for the second case, an overfull by 104.69522pt. Since 104.69522/34 is approximately 3.079, I rounded up.

Similarly for the first version.

enter image description here

If you want some vertical space above the second heading, use \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

...

enter image description here

  • Astounding help, really appreciated! Thank you so much! – MadJens Dec 16 '14 at 23:11
  • @MadJens Some manual work is needed if you want a good product. Add those fixes (\addtolength) only when the document is in its final form: changing the line width might make the fix obsolete. When I work on a document, I ignore the overfull box messages and examine them at the end. – egreg Dec 16 '14 at 23:13
  • Thanks for the tip! One last thing: is it also possible to make the first and last hline bolder/wider so that they stand out a little more? – MadJens Dec 16 '14 at 23:21
  • @MadJens \toprule[20pt] would be much thicker. The same for \bottomrule. But the default thickness is already quite good. – egreg Dec 16 '14 at 23:27
3

the later columns are all left aligned, but the first column is very wide due to

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

which forces the width of the column. perhaps you intended to use \multicolumn so that spanned all the columns rather than forcing the first column to be wide?

tabulary (and tabularx) are unsuited to this kind of table, they work by changing the line breaking width specified in each column. Since your columns mainly consist of numerical data line breaking is not relevant and you would be better to use a standard tabular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.