принудительно установить длинную таблицу по ширине текста

принудительно установить длинную таблицу по ширине текста

Вместо указания ширины каждого столбца в длинной таблице (см. ниже), есть ли способ заставить ее автоматически подстраивать свой размер так, чтобы она соответствовала ширине текста, но не выходила за поля?

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

решение1

Здесь используется тот же подход, что и у Зарко и Скиллмона, но применяется регистр длины, чтобы избежать повторения вычислений 13 раз.

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

демо


\tabcolsepПо краям имеется автоматический зазор , который можно удалить таким образом.

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

Связанный контент