forçar tabela longa para largura de texto

forçar tabela longa para largura de texto

Em vez de especificar a largura de cada coluna em uma tabela longa (veja abaixo), existe uma maneira de fazer com que ela ajuste automaticamente seu tamanho para que corresponda à largura do texto, mas não ultrapasse as margens?

\floatsetup[longtable]{LTcapwidth=\textwidth}
\scriptsize 
\begin{longtable}[c] 
{p{0.045\textwidth}p{0.045\textwidth}p{0.045\textwidth}p{0.045\textwidth}p{0.045\textwidth}p{0.05\textwidth}p{0.045\textwidth}p{0.045\textwidth}p{0.045\textwidth}p{0.045\textwidth} p{0.045\textwidth} p{0.045\textwidth} p{0.045\textwidth}} 
\caption{Insert caption here}
\hline \multicolumn{13}{c} %Removed code for 13 column multiple page table%
 \end{longtable}

Responder1

Isso usa a mesma abordagem de Zarko e Skillmon, mas usa um registro de comprimento para evitar repetir o cálculo 13 vezes.

\documentclass{article}
\usepackage{longtable}
\usepackage{showframe}

\newlength{\mycolwidth}

\begin{document}
\scriptsize 
\setlength{\mycolwidth}{\dimexpr \textwidth/13 - 2\tabcolsep}%
\begin{longtable}[c]{*{13}{p{\mycolwidth}}}
\caption{Insert caption here}
\endfirsthead
\hline 
\multicolumn{13}{c}{Removed code for 13 column multiple page table}\\
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13
\end{longtable}
\end{document}

demonstração


Existe uma folga automática \tabcolsepnas bordas, que pode ser removida desta forma.

\documentclass{article}
\usepackage{longtable}
\usepackage{showframe}

\newlength{\mycolwidth}

\begin{document}
\scriptsize 
\setlength{\mycolwidth}{\dimexpr \textwidth - 24\tabcolsep}%
\divide \mycolwidth by 13

\begin{longtable}[c]{@{}*{13}{p{\mycolwidth}}@{}}
\caption{Insert caption here}
\endfirsthead
\hline 
\multicolumn{13}{c}{Removed code for 13 column multiple page table}\\
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13
\end{longtable}
\end{document}

informação relacionada