Let's first identify what we're referring to when we use the term "table". The typical table
environment is a float, and can contain anything: a paragraph of text, an image, or even a tabular
. Working with the latter - a tabular
- and how to adjust it is what is discussed here. The discussion also applies to array
structures since they provide a math analogue to tabular
.
Consider reading How to influence the position of float environments like figure and table in LaTeX? if you're interested in float-specific placements.
Secondly, understand that a tabular
is a static, two-dimensional construction. As such, it's probably best-suited for representing two dimensions (like age x gender, or region x type). Representing anything more than two dimension may therefore inherently be problematic if not presented "carefully," since the number of elements to tabulate expands geometrically. If you're presenting (say) three dimensions of information by (say) age, gender and ethnicity and the table doesn't fit, perhaps consider breaking this single table into a tabular
by age and gender for each ethnicity. Remember that tables should extend or ease the digestion of the information, so if its representation seems complex, dense or confusing, separation into more elementary components might be your best option.
1. My table/tabular
is too wide. What can I do to make it fit?
The following are possible options to consider (in no particular order):
- If you're presenting data that has large (wide) column headings, consider stacking or abbreviating these to collapse too-wide columns:
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\medskip
% Condense column headers using abbreviations or acronyms
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tbl}&with&twelve&cols&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\[.5\normalbaselineskip]
\multicolumn{12}{l}{%
\footnotesize \texttt{tbl}: \texttt{tabular} title; cols: column title}
\end{tabular}
\bigskip
\begin{tabular}{ *{3}{c} }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking
\begin{tabular}{ *{3}{c} }
This is & & too wide \\
a \texttt{tabular} with & three columns that & to fit \\
& is just & in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking
\begin{tabular}{ *{3}{c} }
\makecell[b]{This is \\ a \texttt{tabular} with} &
\makecell[t]{three columns that \\ is just} &
\makecell{too wide \\ to fit \\ in \texttt{\string\textwidth}.} \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking in a paragraph-style column
\begin{tabular}{ *{3}{c} }
\multicolumn{1}{p{60pt}}{\centering This is a \texttt{tabular} with} &
\multicolumn{1}{p{7em}}{\raggedleft three columns that is just} &
\multicolumn{1}{p{3cm}}{\raggedright too wide to fit in \texttt{\string\textwidth}.} \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
Manual stacking may be tedious. Setting a column heading a fixed-width p{<len>}
-column is a way of providing an automated way of line-breaking (also shown above).
- Allowing columns entries to wrap naturally is possible when using a
p
aragraph-style column specification. This p{<len>}
-style column wraps at <len>
. If you don't know what <len>
should be, tabularx
can help with its flexible X
-column:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{3}{c} }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% tabularx provides a fixed-width table with flexible columns
\begin{tabularx}{\textwidth}{ c X >{\raggedright\arraybackslash}X }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabularx}
\caption{This is a table caption.}
\end{table}
\end{document}
Justified wrapping within the X
-columns may cause overfull \hbox
warnings, which may be avoided by using a \raggedright
setting. Since tabularx
loads array
, column prefixes >{<prefix>}
can be added.
tabulary
provides a similar interface and may also be helpful in this regard.
- Header rotation may also provide some horizontal reduction:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\hd}{\rotatebox{60}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\bigskip
% Condense column headers using rotation
\begin{tabular}{ *{12}{c} }
\hd{This}&\hd{is}&\hd{a}&\hd{\texttt{tabular}}&\hd{with}&\hd{twelve}&
\hd{columns}&\hd{that}&\hd{is}&\hd{just}&\hd{too}&\hd{wide.} \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
Rotational formatting is fairly extreme visually and should be used sparingly.
- Probably the best way of attempting a horizontal fit would be to break the
tabular
is smaller, width-fitting tabular
s. It's the least invasive visually (in general) and perhaps airs out the information for better reader digestion:
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begin{tabular}{ *{6}{c} }
1 & 2 & 3 & 4 & 5 & 6 \\
\hline
This & is & a & \texttt{tabular} & with & twelve \\
\\
7 & 8 & 9 & 10 & 11 & 12 \\
\hline
columns & that & is & just & too & wide.
\end{tabular}
\bigskip
\begin{tabular}{ *{6}{c} }
1 & 2 & 3 & 4 & 5 & 6 \\
\hline
This & is & a & \texttt{tabular} & with & twelve
\end{tabular}
\medskip
\begin{tabular}{ *{6}{c} }
7 & 8 & 9 & 10 & 11 & 12 \\
\hline
columns & that & is & just & too & wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- Consider removing horizontal content to make it fit within the width that you need. You can either remove content manually, although this might be tedious for large
tabular
s. However, if you don't want to remove the content yet still remove a column(s), read Easiest way to delete a column?.
\documentclass{article}
% https://tex.stackexchange.com/a/16607/5764
\usepackage{array}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% Drop/Hide column 10
\begin{tabular}{ *{9}{c} H *{2}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- Consider reducing the horizontal separation between columns. The default document classes define
\tabcolsep
to be 6pt
. For array
s the length used is \arraycolsep
with a default of 5pt
. This may be more than you need. For a multi-column tabular
, reducing the \tabcolsep
could save you valuable points.
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begingroup
\setlength{\tabcolsep}{0.75\tabcolsep}% Reduce \tabcolsep by 25%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
It may be required to limit the scope of the change to \tabcolsep
, hence the use of grouping the \setlength
adjustment (via \begingroup
...\endgroup
or {
...}
).
- Consider reducing the size of fonts used for the
tabular
. If using the default \normalsize
for your document, perhaps \small
or \footnotesize
might make it fit:
\documentclass{article}
\begin{document}
\begin{table}
\centering
% This tabular is too wide
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begingroup
\footnotesize% Change to smaller font from \normalsize
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
See What is the default font size of a LaTeX document? and What point (pt) font size are \Large etc.? for a discussion on fonts and font sizes.
It may be required to limit the scope of the change to the font, hence the use of grouping (via \begingroup
...\endgroup
or {
...}
).
- For just-too-wide
tabular
s, you can resize the entire table to fit within your bounds horizontally using \resizebox{<width>}{<height>}{<tabular>}
where <width>
is at most \linewidth
or \textwidth
(see Difference between \textwidth, \linewidth and \hsize). The notation !
for <height>
will ensure that the aspect ratio of the resizing is kept.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% \resizebox{<width>}{<height>}{<tabular>}
\resizebox{\linewidth}{!}{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
Scaling the tabular
shrinks all the content... text included. If the factor of shrinking is small enough, there may not be a noticeable different between the fonts used in the document and the scaled tabular
.
- Maybe you've conceded that the
tabular
can butt into the margin(s) because any of the above changes are just not sufficient for your needs. However, the default \centering
doesn't set the tabular
in a centred way, so you can set the tabular
inside a \makebox[<width>]
of small enough <width>
(less than \linewidth
) which will automatically centre it within the margin span (see How can I center a too wide table?):
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% This tabular is still too wide, but we'll keep it as-is...
\makebox[\textwidth]{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
- You can rotate the table by 90 degrees (clockwise or counter-clockwise), placing it on its side. Typically pages are taller than they are wider, which may make the
tabular
fit. This, however, would be an extreme adjustment as you're requesting your audience to adjust their point of view and some people may not enjoy this switch between horizontal (left-to-right) and vertical (bottom-to-top) setting:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\rotatebox{90}{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
graphicx
's \rotatebox{<angle>}{<tabular>}
is used to rotate the <tabular>
by <angle>
degrees.
The above example rotates the tabular
only, leaving the caption in its original place. If you want to rotate the entire float - caption included, you can use a sidewaystable
(provided by the rotating
package):
\documentclass{article}
\usepackage{rotating}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\begin{sidewaystable}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{sidewaystable}
\end{document}
Note that a sidewaystable
assumes your table is fairly wide and therefore will occupy most of the text block height during rotation. As such, the default behaviour is to place it on a page of its own.
2. My table/tabular
is too tall. What can I do to make it fit?
Many of the same procedures listed above can be applied vertically in order to adjust your tabular
layout, like font changes, rotation or manually breaking content into multiple tabular
s; some suggestions are listed below.
\arraystretch
is used to stretch (or shrink) each row within a tabular
. Perhaps your \documentclass
increased this. You can adjust it using \renewcommand
:
\documentclass{article}
\begin{document}
\begin{table}
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}%
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{1}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}%
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{0.8}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}
\caption{This is a table caption.}
\end{table}
\end{document}
- Consider cutting out chunks of rows and stacking them horizontally rather than keeping the content in a vertical fashion.
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\bigskip
\begin{tabular}{ c c @{\hspace{2em}} c c }
1&This & 1&This \\
\hline
2&is & 8&that \\
3&a & 9&is \\
4&\texttt{tabular} & 10&just \\
5&with & 11&too \\
6&twelve & 12&tall. \\
7&rows
\end{tabular}
\bigskip
\begin{tabular}[t]{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\ 7&rows
\end{tabular}\hspace{2em}%
\begin{tabular}[t]{ c c }
1&This \\
\hline
8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- Reducing the font size also reduces the line height and consequently the vertical span of a
tabular
:
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\hspace{2em}%
\begingroup
\small% Change to smaller font size from \normalsize
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
Again, here, scoping might be required to limit font changes.
graphicx
's \scalebox{<factor>}
or \resizebox{<width>}{<height>}
is an option. You can specify an appropriate height-fitting <height>
length or portion. A <width>
of !
ensures to maintain the aspect ratio during resizing:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\hspace{2em}%
\resizebox{!}{.8\height}{%
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
The following example is taken directly from the longtable
documentation and illustrates the construction of the longtable
environment components in order to break a table across multiple pages (with a "continued caption"):
\documentclass{article}
\usepackage{longtable}
\def\v{\char`}
\begin{document}
% Note: Various parts of the following table will
% *not* line up correctly until this document has been run
% through LaTeX several times. This is a characteristic feature of
% this package, as described below.
\begin{longtable}{@{*}r||p{1in}@{*}}
KILLED & LINE!!!! \kill
\caption
[An optional table caption (used in the list of tables)]
{A long table\label{long}} \\
\hline\hline
\multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \\
\textsc{First} & \textsc{Second} \\
\hline\hline
\endfirsthead
\caption[]{(continued)} \\
\hline\hline
\multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \\
\textbf{First} & \textbf{Second} \\
\hline\hline
\endhead
\hline
This goes at the & bottom. \\
\hline
\endfoot
\hline
These lines will & appear \\
in place of the & usual foot \\
at the end & of the table \\
\hline
\endlastfoot
\texttt{longtable} columns are specified & in the \\
same way as in the \texttt{tabular} & environment. \\
``\verb~@{*}r||p{1in}@{*}~'' & in this case. \\
Each row ends with a & ``\verb|\\|'' command. \\
The ``\verb|\\|'' command has an & optional \\
argument, just as in & the \\
\texttt{tabular} & environment. \\[10pt]
See the effect of ``\verb|\\[10pt]|'' & ? \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Also ``\verb|\hline|'' may be used, & as in \texttt{tabular}. \\
\hline
That was a ``\verb|\hline|'' & . \\
\hline\hline
That was ``\verb|\hline\hline|'' & . \\
\multicolumn{2}{||c||}%
{This is a \ttfamily\v\\multicolumn\v{2\v}\v{||c||\v}} \\
If a page break occurs at a ``\verb|\hline|'' then & a line is drawn \\
at the bottom of one page and at the & top of the next. \\
\hline
The ``\verb|[t] [b] [c]|'' argument of \texttt{tabular} & can not be used. \\
The optional argument may be one of & ``\verb|[l] [r] [c]|'' \\
to specify whether the table should be & adjusted \\
to the left, right & or centrally. \\
\hline\hline
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Some lines may take up a lot of space, like this: &
\raggedleft This last column is a ``\texttt{p}'' column so this
``row'' of the table can take up several lines. Note however that
\TeX\ will never break a page within such a row. Page breaks only
occur between rows of the table or at ``\verb|\hline|'' commands.
\tabularnewline
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
\hline
Lots\footnote{This is a footnote.} of lines & like this. \\
Lots of lines & like this\footnote{\texttt{longtable} takes special
precautions, so that footnotes may also be used in `\texttt{p}' columns.} \\
\hline
Lots of lines & like this. \\
Lots of lines & like this.
\end{longtable}
\end{document}
3. My tabular
is too wide and too tall for where I placed it. What can I do?
Typically one can combine the above methods for width/height improvements. There may be some incompatible choices (like resizing a longtable
, for example).