How to fix the width of longtable LATEX

14.5k views Asked by At

I want to set the width of my longtable so it fits within the page and not crops out. I have 206 columns and 17 rows.

I use tablesgenerator.com to get my longtable, but the option "Scale table to text width" doesn't work with longtable, could use some help. (Latex beginner here).

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

This is what it looks like

Image

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On

Assuming you mean 206 rows and not columns, then you could try the following strategies:

  • put the table on landscape pages

  • use a smaller font

  • reduce the margins of your document to have more space

  • reduce the space between columns


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

enter image description here