首页 > 解决方案 > 如何修复longtable LATEX的宽度

问题描述

我想设置我的宽度,longtable使其适合页面而不是裁剪。我有 206 列和 17 行。

我使用 tablesgenerator.com 来获取我的longtable,但是“将表格缩放到文本宽度”选项不适用于longtable,可以使用一些帮助。(这里是乳胶初学者)。

\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

\begin{longtable}{@{}lllllllllllllllll@{}}
\toprule
\textbf{SN} & \textbf{zhelio} & \textbf{zhelio\_un} & \textbf{zCMB} & 
\textbf{zCMB\_un} & \textbf{Peak\_MJD} & \textbf{Peak\_MJD\_un} & \textbf{x1} 
& \textbf{x1\_un} & \textbf{c} & \textbf{c\_un} & \textbf{mB} & 
\textbf{mB\_un} & \textbf{t} & \textbf{t\_un} & \textbf{Host\_logmass} & 
\textbf{Host\_logmass\_un} \\* \midrule
\endhead

%table stuff here...

\caption{}
\label{tab:my-table}\\
\end{longtable}

\end{document}

这就是它的样子

图片

标签: latexwidthlongtable

解决方案


假设您的意思是 206 行而不是列,那么您可以尝试以下策略:

  • 将表格放在横向页面上

  • 使用较小的字体

  • 减少文档的边距以腾出更多空间

  • 减少列之间的空间


\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[vmargin=2cm]{geometry}
\usepackage{lscape}

\begin{document}

\begin{landscape}
\small
\setlength{\tabcolsep}{2pt}
\begin{longtable}{@{}lllllllllllllllll@{}}
\toprule
\textbf{SN} & \textbf{zhelio} & \textbf{zhelio\_un} & \textbf{zCMB} & 
\textbf{zCMB\_un} & \textbf{Peak\_MJD} & \textbf{Peak\_MJD\_un} & \textbf{x1} 
& \textbf{x1\_un} & \textbf{c} & \textbf{c\_un} & \textbf{mB} & 
\textbf{mB\_un} & \textbf{t} & \textbf{t\_un} & \textbf{Host\_logmass} & 
\textbf{Host\_logmass\_un} \\* \midrule
\endhead

%table stuff here...

\caption{}
\label{tab:my-table}\\
\end{longtable}
\end{landscape}
\end{document}

在此处输入图像描述


推荐阅读