3

High everyone,

I'm having the problem that certain tables, like the one i'm going to quote here, are going beyond the textwidth eventhough I use the options \textwidth with tabulary.

The table has the following code:

\usepackage{tabulary}
\usepackage{tabularx}
\begin{table}[htbp]
   \centering
  \caption{Categorization of cantons}
  \scriptsize
    \begin{tabulary}{\textwidth}{|L|L|L|L|L|}
    \hline
    \multicolumn{1}{|c|}{\textbf{Central Switzerland (C)}} & \multicolumn{1}{c|}{\textbf{High Alps (HA)}} & \multicolumn{1}{c|}{\textbf{Northeast Switzerland (NE)}} & \multicolumn{1}{c|}{\textbf{Northwest Switzerland (NW)}} & \multicolumn{1}{c|}{\textbf{West Switzerland (W)}} \bigstrut\\
    \hline
    Lucerne (LU) & Grisons (GR) & Glarus (GL) & Zurich (ZH) & Fribourg (FR) \bigstrut[t]\\
    Central Switzerland (C) & Tessin (TI) & Schaffhausen (SH) & Solothurn (SO) & Vaud (VD) \\
    & Valais (VS) & Appenzell (AP) & Basel-Stadt (BS) & Neuchâtel (NE) \\
     &       & St. Gallen (SG) & Basel-Land (BL) & Geneva (GE) \\
     &       & Thurgau (TG) & Aargau (AG) &  \bigstrut[b]\\
    \hline
    \end{tabulary}%
    \vspace{5pt}
    \captionsetup{font={scriptsize}}
    \caption*{Source: Eidgenössischer Turnverein (1869), p. 67-69, own illustration}
  \label{tab:addlabel}%
\end{table}%

Here is a picture of the table: Table too wide
How can I make the width of the table automatically fit the textwidth? I don't mind if the first row (i.e. Central Switzerland, High Alps, etc.) would have to be squeezed into two lines as long as it makes the table fit into the textwidth. Is there a command that manages to do that and that I can readily use for future tables?

Many thanks for your help!

  • Please make your code compilable and as short as possible. One table line should be enough. We need your documentclass and so on in order to reproduce your problem. Thanks. – LaRiFaRi Dec 15 '14 at 12:00
6

Please always post complete documents showing all packages used. Your code had several commands not defined by the packages I guessed so I deleted them here. The main problem was that you over-rode the L specifier with c which does not allow line breaking so forced all the entries to be too wide.

\documentclass[a4paper]{article}
\usepackage{tabulary}
\begin{document}

\begin{table}[htbp]
   \centering
  \caption{Categorization of cantons}
  \scriptsize
    \begin{tabulary}{\textwidth}{|L|L|L|L|L|}
    \hline
    \centering\textbf{Central Switzerland (C)} & 
\centering\textbf{High Alps (HA)} & 
\centering\textbf{Northeast Switzerland (NE)} & 
\centering\textbf{Northwest Switzerland (NW)} &
\centering\textbf{West Switzerland (W)}\tabularnewline
    \hline
    Lucerne (LU) & Grisons (GR) & Glarus (GL) & Zurich (ZH) & Fribourg (FR) \\
    Central Switzerland (C) & Tessin (TI) & Schaffhausen (SH) & Solothurn (SO) & Vaud (VD) \\
    & Valais (VS) & Appenzell (AP) & Basel-Stadt (BS) & Neuchâtel (NE) \\
     &       & St. Gallen (SG) & Basel-Land (BL) & Geneva (GE) \\
     &       & Thurgau (TG) & Aargau (AG) &  \\
    \hline
    \end{tabulary}%
    \vspace{5pt}
%    \captionsetup{font={scriptsize}}
    \caption{Source: Eidgenössischer Turnverein (1869), p. 67-69, own illustration}
  \label{tab:addlabel}%
\end{table}%

\end{document}
4

If you want to have all columns with the same width and use the maximum width of your text, you should go with tabularx here:

% arara: pdflatex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{booktabs, tabularx, threeparttable}
\usepackage{ragged2e, array}
\newcolumntype{Z}{>{\raggedright\arraybackslash}X}
\usepackage{microtype}

\begin{document}
\begin{table}[htbp]
    \centering
    \begin{threeparttable}
    \caption{Categorization of cantons}
    \begin{tabularx}{\textwidth}{*{5}{Z}}
        \toprule
        \textbf{Central Switzerland~(C)} &\textbf{High Alps~(HA)} & \textbf{Northeast Switzerland~(NE)} & \textbf{Northwest Switzerland~(NW)} & \textbf{West Switzerland~(W)} \\
        \midrule
        Lucerne~(LU) & Grisons~(GR) & Glarus~(GL) & Zurich~(ZH) & Fribourg~(FR) \\
        Central Switzerland~(C) & Tessin~(TI) & Schaff\-hau\-sen~(SH) & So\-lo\-thurn~(SO) & Vaud~(VD) \\
        & Valais (VS) & Appen\-zell~(AP) & Basel-Stadt (BS) & Neu\-châ\-tel~(NE) \\
        &       & St.~Gal\-len~(SG) & Basel-Land (BL) & Geneva~(GE) \\
        &       & Thurgau~(TG) & Aargau~(AG) & \\
        \bottomrule
    \end{tabularx}
    \begin{tablenotes}
    \item Source: Eidgenössischer Turnverein (1869), p.~67-69, own illustration
    \end{tablenotes}
    \end{threeparttable}
    \label{tab:addlabel}%
\end{table}%
\end{document}

enter image description here

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.