Tabela ainda muito larga usando \textwidth e tabulary

Tabela ainda muito larga usando \textwidth e tabulary

Alto pessoal,

Estou tendo o problema de que certas tabelas, como a que vou citar aqui, estão ultrapassando a largura do texto mesmo eu usando as opções \textwidth com tabulary.

A tabela possui o seguinte código:

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

Aqui está uma imagem da tabela: Mesa muito larga
Como posso fazer com que a largura da tabela se ajuste automaticamente à largura do texto? Não me importo se a primeira linha (ou seja, Suíça Central, Altos Alpes, etc.) tiver que ser comprimida em duas linhas, desde que faça com que a tabela caiba na largura do texto. Existe um comando que consegue fazer isso e que eu possa usar facilmente em tabelas futuras?

Muito obrigado pela sua ajuda!

Responder1

Por favor, sempre publique documentos completos mostrando todos os pacotes usados. Seu código tinha vários comandos não definidos pelos pacotes, imaginei, então os excluí aqui. O principal problema foi que você cancelou o Lespecificador cque não permite quebra de linha, forçando todas as entradas a serem muito largas.

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

Responder2

Se você deseja ter todas as colunas com a mesma largura e usar a largura máxima do seu texto, você deve seguir tabularxaqui:

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

insira a descrição da imagem aqui

informação relacionada