LaTeX table too wide. How to make it fit?
Asked Answered
E

3

69

I just started to learn latex and now I'm trying to create a table. This is my code:

\begin{table}
\caption{Top Scorers}
\begin{tabular}{ l l }
    \hline
    \bf Goals & \bf Players\\
    \hline
    4 & First Last, First Last, First Last, First Last\\
    3 & First Last\\
    2 & First Last\\
    1 & First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last, First Last\\
    \hline
\end{tabular}
\end{table}

The problem is that the table is wider than the page. I was hoping that it would automatically fit to the page like normal text does, but it didn't. How do I tell latex to make the table fit to the page?

Elburt answered 8/5, 2010 at 15:50 Comment(1)
See this FAQ: My table doesn't fit; what are my options?Salomon
B
58

Use p{width} column specifier: e.g. \begin{tabular}{ l p{10cm} } will put column's content into 10cm-wide parbox, and the text will be properly broken to several lines, like in normal paragraph.

You can also use tabular* environment to specify width for the entire table.

Biddick answered 8/5, 2010 at 15:59 Comment(4)
Do I have to set a fixed size for p{} or can I tell it to use the rest of the space?Elburt
@Erik: AFAIK you need a fixed size.Biddick
For tabular*, the implementation is as follows: \begin{tabular*}{\textwidth}{|r|}Commencement
Could you add an example showcasing this? It doesn't seem to work for meMissus
C
57

You have to take whole columns under resizebox. This code worked for me

\begin{table}[htbp]
\caption{Sample Table.}\label{tab1}
\resizebox{\columnwidth}{!}{\begin{tabular}{|l|l|l|l|l|}
\hline
URL &  First Time Visit & Last Time Visit & URL Counts & Value\\
\hline
https://web.facebook.com/ & 1521241972 & 1522351859 & 177 & 56640\\
http://localhost/phpmyadmin/ & 1518413861 & 1522075694 & 24 & 39312\\
https://mail.google.com/mail/u/ & 1516596003 & 1522352010 & 36 & 33264\\
https://github.com/shawon100& 1517215489 & 1522352266 & 37 & 27528\\
https://www.youtube.com/ & 1517229227 & 1521978502 & 24 & 14792\\
\hline
\end{tabular}}
\end{table}
Concise answered 9/5, 2018 at 10:38 Comment(2)
This changes the font size in the table, it'll be hard to read.Sandblast
one of the best answers. Works for me like a silver bullet.Lashoh
K
8

You can use these options as well, either use \footnotesize or \tiny. This would really help in fitting big tables.

\begin{table}[htbp]
\footnotesize
\caption{Information on making the table size small}
\label{table:table1}
\begin{tabular}{ll}
    \toprule
    S.No       & HMD           \\
    \midrule
    1          & HTC Vive \\
    2          & HTC Vive Pro   \\
    \bottomrule
\end{tabular}
\end{table}
Kislev answered 26/8, 2020 at 10:14 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.