Make a LaTeX table fit the page width
Help centre › LaTeX › Tables · Packages: tabularx, booktabs
Use \usepackage{tabularx} and \begin{tabularx}{\linewidth}{l X X}: the X columns share the remaining width and wrap their text, so the table is exactly as wide as the text. For a table that is only slightly too wide, a smaller font (\small) or less column spacing (\setlength{\tabcolsep}{4pt}) is often enough; scaling with \resizebox works but makes the font size inconsistent.
A complete example
A whole document: paste it into an empty project and compile it.
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Methods compared.}\label{tab:methods}
\begin{tabularx}{\linewidth}{l >{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}X}
\toprule
Method & Strengths & Limitations \\
\midrule
Survey & Reaches many people at low cost and gives comparable answers
& Answers are self-reported and response rates can be low \\
Interview & Gives depth and lets the researcher follow up on answers
& Takes time and the sample is small \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}tabularx: X columns
tabularx takes the total width as its first argument and makes every X column as wide as needed to reach it, all X columns equally wide. Text in X columns wraps like a paragraph. Use \linewidth (the current text or column width); in a two-column table*, \textwidth.
X columns are justified by default, which leaves wide gaps in narrow columns. >{\raggedright\arraybackslash}X sets them ragged-right; define it once with \newcolumntype{L}{>{\raggedright\arraybackslash}X} and write L.
p{} columns: fixed widths that wrap
In a plain tabular, p{4cm} makes a column of that width whose text wraps. It is enough when you know the widths you want; the table's total width is the sum of the columns plus the spacing between them.
\begin{tabular}{l p{5cm} p{5cm}}Slightly too wide: smaller font and tighter spacing
Put the size command inside the table environment, before the tabular; it then applies to the table only. \tabcolsep is half the space between columns (6pt by default).
\documentclass{article}
\begin{document}
\begin{table}[htbp]
\centering
\small
\setlength{\tabcolsep}{4pt}
\caption{Smaller type and tighter columns.}
\begin{tabular}{lrrrrrrr}
\hline
Group & Mean & SD & Min & Q1 & Median & Q3 & Max \\
\hline
Control & 12.4 & 3.1 & 5.0 & 10.2 & 12.5 & 14.6 & 19.8 \\
Treated & 15.1 & 2.8 & 8.3 & 13.0 & 15.2 & 17.1 & 22.4 \\
\hline
\end{tabular}
\end{table}
\end{document}\resizebox: a last resort
\resizebox{\linewidth}{!}{\begin{tabular}…\end{tabular}} (graphicx) scales the whole table to the width. It always fits, but every table ends up with a different font size, often much smaller than the text, which journals and examiners notice; it also scales small tables up. If you use it, scale only tables that are too wide: adjustbox with \begin{adjustbox}{max width=\linewidth} shrinks a table that is too wide and leaves others alone.
Common mistakes
\textwidthin a one-columntableof a two-column paper: the table spills into the other column. Use\linewidth(or\columnwidth), andtable*for full width.- An
Xcolumn for numbers: numbers should not wrap; keep them inr,cor siunitxScolumns and giveXonly to text. - Nesting
tabularxinside\resizebox: tabularx already sets the width. - A size command such as
\smallplaced after\begin{tabular}: it applies to the first cell only. - A table that is too wide even with these: turn it sideways (see A landscape table or page) or split it.
In journal templates
- In two-column classes (IEEEtran, elsarticle's
twocolumnoptions, revtex), a table intableis one column wide;table*spans both columns and goes at the top of a page. Use\linewidthinside either, and it adapts. - Many journals' instructions ask for the table text at the same size as the body or one size smaller; that rules out
\resizeboxin practice.
Errors you may meet
- Overfull \hbox (<n>pt too wide) in paragraph at lines <a>--<b>A line sticks out into the margin because TeX found no acceptable place to break it: a long URL or word, or an image or equation wider than the column.
- Extra alignment tab has been changed to \cr.A table or matrix row has more & cells than the column specification allows. Add a column to {…}, remove an &, or add a missing \\.
- LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
In Manulyx
Insert → Table puts a table environment in place, and pasting a range copied from a spreadsheet (two or more rows and columns) goes in as a LaTeX table, with booktabs rules when the paper loads booktabs and \hline otherwise; a notice offers the plain text back.
Write in Manulyx for free · Journal templates
Related
- Merge cells in a LaTeX table: multirow and multicolumnMerge table cells across columns with \multicolumn and across rows with \multirow (multirow package), with booktabs rules and \cline/\cmidrule.
- Professional-looking tables in LaTeX with booktabsMake LaTeX tables look typeset: booktabs rules (\toprule, \midrule, \bottomrule, \cmidrule), no vertical lines, and aligned numbers.
- A landscape table or page in LaTeXTurn a wide table sideways: pdflscape's landscape environment rotates whole pages (upright on screen); rotating's sidewaystable rotates a float.
- A table across several pages in LaTeX (longtable)Break a long LaTeX table across pages with longtable, repeating the header on each page and adding a "continued" note, with booktabs rules.
- Table notes and footnotes in a LaTeX table (threeparttable)Add notes under a LaTeX table with markers in the cells, using threeparttable's \tnote and tablenotes, and why \footnote inside a table goes missing.
The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained