My table doesn't fit; what are my options?
up vote
56
down vote
favorite
I have a table that I want to insert on a page, but at least one (perhaps both) of the following conditions are met:
The table is too wide to fit within the text block or page. That is, I'm exceeding some horizontal restriction.
The table is too tall to fit within the text block or page. That is, I'm exceeding some vertical restriction.
What are my options to make this table fit? If it doesn't fit, regardless of my attempts, what other options exist?
tables page-breaking width height
add a comment |
up vote
56
down vote
favorite
I have a table that I want to insert on a page, but at least one (perhaps both) of the following conditions are met:
The table is too wide to fit within the text block or page. That is, I'm exceeding some horizontal restriction.
The table is too tall to fit within the text block or page. That is, I'm exceeding some vertical restriction.
What are my options to make this table fit? If it doesn't fit, regardless of my attempts, what other options exist?
tables page-breaking width height
6
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
5
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25
add a comment |
up vote
56
down vote
favorite
up vote
56
down vote
favorite
I have a table that I want to insert on a page, but at least one (perhaps both) of the following conditions are met:
The table is too wide to fit within the text block or page. That is, I'm exceeding some horizontal restriction.
The table is too tall to fit within the text block or page. That is, I'm exceeding some vertical restriction.
What are my options to make this table fit? If it doesn't fit, regardless of my attempts, what other options exist?
tables page-breaking width height
I have a table that I want to insert on a page, but at least one (perhaps both) of the following conditions are met:
The table is too wide to fit within the text block or page. That is, I'm exceeding some horizontal restriction.
The table is too tall to fit within the text block or page. That is, I'm exceeding some vertical restriction.
What are my options to make this table fit? If it doesn't fit, regardless of my attempts, what other options exist?
tables page-breaking width height
tables page-breaking width height
edited Dec 29 '17 at 23:07
asked Oct 6 '16 at 12:00
Werner
432k609521633
432k609521633
6
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
5
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25
add a comment |
6
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
5
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25
6
6
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
5
5
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25
add a comment |
1 Answer
1
active
oldest
votes
up vote
66
down vote
accepted
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 an 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 \[.5normalbaselineskip]
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{stringtextwidth}. \
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{stringtextwidth}. \
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{stringtextwidth}.} \
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{stringtextwidth}.} \
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. Thisp{<len>}
-style column wraps at<len>
. If you don't know what<len>
should be,tabularx
can help with its flexibleX
-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{stringtextwidth}. \
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 >{raggedrightarraybackslash}X }
This is a texttt{tabular} with&three columns that is just&too wide to fit in texttt{stringtextwidth}. \
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 overfullhbox
warnings, which may be avoided by using araggedright
setting. Sincetabularx
loadsarray
, 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 attempt a horizontal fit would be to break the
tabular
is smaller, width-fittingtabular
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=hboxbgroup}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 be6pt
. Forarray
s the length used ifarraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing thetabcolsep
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.75tabcolsep}% 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 thesetlength
adjustment (viabegingroup
...endgroup
or{
...}
).
Consider reducing the size of fonts used for the
tabular
. If using the defaultnormalsize
for your document, perhapssmall
orfootnotesize
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 usingresizebox{<width>}{<height>}{<tabular>}
where<width>
is at mostlinewidth
ortextwidth
(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 scaledtabular
.
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 defaultcentering
doesn't set thetabular
in a centred way, so you can set thetabular
inside amakebox[<width>]
of small enough<width>
(less thanlinewidth
) 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
'srotatebox{<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 asidewaystable
(provided by therotating
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 atabular
. Perhaps yourdocumentclass
increased this. You can adjust it usingrenewcommand
:
documentclass{article}
begin{document}
begin{table}
begin{minipage}{0.3333linewidth}
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.3333linewidth}
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.3333linewidth}
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
'sscalebox{<factor>}
orresizebox{<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{!}{.8height}{%
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}
If your
tabular
is just too tall, you can consider breaking it across the page boundary manually (that is, setting separatetabular
s to fit on each page). This may require the use of separate floats (and perhaps continued captions as well). However, there are packages that can assist with such automated breaking:longtable
,supertabular
andxtab
are a couple such packages. More packages are listed on CTAN. Also see How can I make a table that takes up more than a single page? or Make a table span multiple pages.
The following example is taken directly from the
longtable
documentation and illustrates the construction of thelongtable
environment components in order to break a table across multiple packages (with a "continued caption"):
documentclass{article}
usepackage{longtable}
defv{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 tablelabel{long}} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \
textsc{First} & textsc{Second} \
hlinehline
endfirsthead
caption{(continued)} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \
textbf{First} & textbf{Second} \
hlinehline
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|'' & . \
hlinehline
That was ``verb|hlinehline|'' & . \
multicolumn{2}{||c||}%
{This is a ttfamilyv\multicolumnv{2v}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. \
hlinehline
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
Lotsfootnote{This is a footnote.} of lines & like this. \
Lots of lines & like thisfootnote{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).
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text inc
/l
/r
columns, and the usual fix isp
/X
columns, so an example of that would be useful.
– Torbjørn T.
Oct 6 '16 at 12:09
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (GM
org.~m.
or alike) or an arbitrary symbol such as(dagger)
(†),(*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).
– boycott.se - yo'
Oct 6 '16 at 12:42
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
|
show 5 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
66
down vote
accepted
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 an 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 \[.5normalbaselineskip]
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{stringtextwidth}. \
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{stringtextwidth}. \
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{stringtextwidth}.} \
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{stringtextwidth}.} \
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. Thisp{<len>}
-style column wraps at<len>
. If you don't know what<len>
should be,tabularx
can help with its flexibleX
-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{stringtextwidth}. \
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 >{raggedrightarraybackslash}X }
This is a texttt{tabular} with&three columns that is just&too wide to fit in texttt{stringtextwidth}. \
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 overfullhbox
warnings, which may be avoided by using araggedright
setting. Sincetabularx
loadsarray
, 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 attempt a horizontal fit would be to break the
tabular
is smaller, width-fittingtabular
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=hboxbgroup}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 be6pt
. Forarray
s the length used ifarraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing thetabcolsep
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.75tabcolsep}% 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 thesetlength
adjustment (viabegingroup
...endgroup
or{
...}
).
Consider reducing the size of fonts used for the
tabular
. If using the defaultnormalsize
for your document, perhapssmall
orfootnotesize
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 usingresizebox{<width>}{<height>}{<tabular>}
where<width>
is at mostlinewidth
ortextwidth
(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 scaledtabular
.
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 defaultcentering
doesn't set thetabular
in a centred way, so you can set thetabular
inside amakebox[<width>]
of small enough<width>
(less thanlinewidth
) 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
'srotatebox{<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 asidewaystable
(provided by therotating
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 atabular
. Perhaps yourdocumentclass
increased this. You can adjust it usingrenewcommand
:
documentclass{article}
begin{document}
begin{table}
begin{minipage}{0.3333linewidth}
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.3333linewidth}
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.3333linewidth}
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
'sscalebox{<factor>}
orresizebox{<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{!}{.8height}{%
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}
If your
tabular
is just too tall, you can consider breaking it across the page boundary manually (that is, setting separatetabular
s to fit on each page). This may require the use of separate floats (and perhaps continued captions as well). However, there are packages that can assist with such automated breaking:longtable
,supertabular
andxtab
are a couple such packages. More packages are listed on CTAN. Also see How can I make a table that takes up more than a single page? or Make a table span multiple pages.
The following example is taken directly from the
longtable
documentation and illustrates the construction of thelongtable
environment components in order to break a table across multiple packages (with a "continued caption"):
documentclass{article}
usepackage{longtable}
defv{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 tablelabel{long}} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \
textsc{First} & textsc{Second} \
hlinehline
endfirsthead
caption{(continued)} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \
textbf{First} & textbf{Second} \
hlinehline
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|'' & . \
hlinehline
That was ``verb|hlinehline|'' & . \
multicolumn{2}{||c||}%
{This is a ttfamilyv\multicolumnv{2v}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. \
hlinehline
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
Lotsfootnote{This is a footnote.} of lines & like this. \
Lots of lines & like thisfootnote{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).
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text inc
/l
/r
columns, and the usual fix isp
/X
columns, so an example of that would be useful.
– Torbjørn T.
Oct 6 '16 at 12:09
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (GM
org.~m.
or alike) or an arbitrary symbol such as(dagger)
(†),(*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).
– boycott.se - yo'
Oct 6 '16 at 12:42
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
|
show 5 more comments
up vote
66
down vote
accepted
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 an 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 \[.5normalbaselineskip]
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{stringtextwidth}. \
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{stringtextwidth}. \
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{stringtextwidth}.} \
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{stringtextwidth}.} \
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. Thisp{<len>}
-style column wraps at<len>
. If you don't know what<len>
should be,tabularx
can help with its flexibleX
-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{stringtextwidth}. \
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 >{raggedrightarraybackslash}X }
This is a texttt{tabular} with&three columns that is just&too wide to fit in texttt{stringtextwidth}. \
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 overfullhbox
warnings, which may be avoided by using araggedright
setting. Sincetabularx
loadsarray
, 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 attempt a horizontal fit would be to break the
tabular
is smaller, width-fittingtabular
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=hboxbgroup}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 be6pt
. Forarray
s the length used ifarraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing thetabcolsep
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.75tabcolsep}% 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 thesetlength
adjustment (viabegingroup
...endgroup
or{
...}
).
Consider reducing the size of fonts used for the
tabular
. If using the defaultnormalsize
for your document, perhapssmall
orfootnotesize
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 usingresizebox{<width>}{<height>}{<tabular>}
where<width>
is at mostlinewidth
ortextwidth
(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 scaledtabular
.
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 defaultcentering
doesn't set thetabular
in a centred way, so you can set thetabular
inside amakebox[<width>]
of small enough<width>
(less thanlinewidth
) 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
'srotatebox{<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 asidewaystable
(provided by therotating
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 atabular
. Perhaps yourdocumentclass
increased this. You can adjust it usingrenewcommand
:
documentclass{article}
begin{document}
begin{table}
begin{minipage}{0.3333linewidth}
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.3333linewidth}
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.3333linewidth}
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
'sscalebox{<factor>}
orresizebox{<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{!}{.8height}{%
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}
If your
tabular
is just too tall, you can consider breaking it across the page boundary manually (that is, setting separatetabular
s to fit on each page). This may require the use of separate floats (and perhaps continued captions as well). However, there are packages that can assist with such automated breaking:longtable
,supertabular
andxtab
are a couple such packages. More packages are listed on CTAN. Also see How can I make a table that takes up more than a single page? or Make a table span multiple pages.
The following example is taken directly from the
longtable
documentation and illustrates the construction of thelongtable
environment components in order to break a table across multiple packages (with a "continued caption"):
documentclass{article}
usepackage{longtable}
defv{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 tablelabel{long}} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \
textsc{First} & textsc{Second} \
hlinehline
endfirsthead
caption{(continued)} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \
textbf{First} & textbf{Second} \
hlinehline
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|'' & . \
hlinehline
That was ``verb|hlinehline|'' & . \
multicolumn{2}{||c||}%
{This is a ttfamilyv\multicolumnv{2v}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. \
hlinehline
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
Lotsfootnote{This is a footnote.} of lines & like this. \
Lots of lines & like thisfootnote{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).
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text inc
/l
/r
columns, and the usual fix isp
/X
columns, so an example of that would be useful.
– Torbjørn T.
Oct 6 '16 at 12:09
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (GM
org.~m.
or alike) or an arbitrary symbol such as(dagger)
(†),(*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).
– boycott.se - yo'
Oct 6 '16 at 12:42
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
|
show 5 more comments
up vote
66
down vote
accepted
up vote
66
down vote
accepted
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 an 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 \[.5normalbaselineskip]
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{stringtextwidth}. \
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{stringtextwidth}. \
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{stringtextwidth}.} \
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{stringtextwidth}.} \
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. Thisp{<len>}
-style column wraps at<len>
. If you don't know what<len>
should be,tabularx
can help with its flexibleX
-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{stringtextwidth}. \
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 >{raggedrightarraybackslash}X }
This is a texttt{tabular} with&three columns that is just&too wide to fit in texttt{stringtextwidth}. \
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 overfullhbox
warnings, which may be avoided by using araggedright
setting. Sincetabularx
loadsarray
, 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 attempt a horizontal fit would be to break the
tabular
is smaller, width-fittingtabular
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=hboxbgroup}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 be6pt
. Forarray
s the length used ifarraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing thetabcolsep
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.75tabcolsep}% 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 thesetlength
adjustment (viabegingroup
...endgroup
or{
...}
).
Consider reducing the size of fonts used for the
tabular
. If using the defaultnormalsize
for your document, perhapssmall
orfootnotesize
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 usingresizebox{<width>}{<height>}{<tabular>}
where<width>
is at mostlinewidth
ortextwidth
(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 scaledtabular
.
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 defaultcentering
doesn't set thetabular
in a centred way, so you can set thetabular
inside amakebox[<width>]
of small enough<width>
(less thanlinewidth
) 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
'srotatebox{<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 asidewaystable
(provided by therotating
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 atabular
. Perhaps yourdocumentclass
increased this. You can adjust it usingrenewcommand
:
documentclass{article}
begin{document}
begin{table}
begin{minipage}{0.3333linewidth}
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.3333linewidth}
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.3333linewidth}
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
'sscalebox{<factor>}
orresizebox{<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{!}{.8height}{%
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}
If your
tabular
is just too tall, you can consider breaking it across the page boundary manually (that is, setting separatetabular
s to fit on each page). This may require the use of separate floats (and perhaps continued captions as well). However, there are packages that can assist with such automated breaking:longtable
,supertabular
andxtab
are a couple such packages. More packages are listed on CTAN. Also see How can I make a table that takes up more than a single page? or Make a table span multiple pages.
The following example is taken directly from the
longtable
documentation and illustrates the construction of thelongtable
environment components in order to break a table across multiple packages (with a "continued caption"):
documentclass{article}
usepackage{longtable}
defv{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 tablelabel{long}} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \
textsc{First} & textsc{Second} \
hlinehline
endfirsthead
caption{(continued)} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \
textbf{First} & textbf{Second} \
hlinehline
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|'' & . \
hlinehline
That was ``verb|hlinehline|'' & . \
multicolumn{2}{||c||}%
{This is a ttfamilyv\multicolumnv{2v}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. \
hlinehline
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
Lotsfootnote{This is a footnote.} of lines & like this. \
Lots of lines & like thisfootnote{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).
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 an 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 \[.5normalbaselineskip]
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{stringtextwidth}. \
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{stringtextwidth}. \
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{stringtextwidth}.} \
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{stringtextwidth}.} \
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. Thisp{<len>}
-style column wraps at<len>
. If you don't know what<len>
should be,tabularx
can help with its flexibleX
-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{stringtextwidth}. \
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 >{raggedrightarraybackslash}X }
This is a texttt{tabular} with&three columns that is just&too wide to fit in texttt{stringtextwidth}. \
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 overfullhbox
warnings, which may be avoided by using araggedright
setting. Sincetabularx
loadsarray
, 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 attempt a horizontal fit would be to break the
tabular
is smaller, width-fittingtabular
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=hboxbgroup}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 be6pt
. Forarray
s the length used ifarraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing thetabcolsep
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.75tabcolsep}% 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 thesetlength
adjustment (viabegingroup
...endgroup
or{
...}
).
Consider reducing the size of fonts used for the
tabular
. If using the defaultnormalsize
for your document, perhapssmall
orfootnotesize
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 usingresizebox{<width>}{<height>}{<tabular>}
where<width>
is at mostlinewidth
ortextwidth
(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 scaledtabular
.
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 defaultcentering
doesn't set thetabular
in a centred way, so you can set thetabular
inside amakebox[<width>]
of small enough<width>
(less thanlinewidth
) 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
'srotatebox{<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 asidewaystable
(provided by therotating
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 atabular
. Perhaps yourdocumentclass
increased this. You can adjust it usingrenewcommand
:
documentclass{article}
begin{document}
begin{table}
begin{minipage}{0.3333linewidth}
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.3333linewidth}
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.3333linewidth}
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
'sscalebox{<factor>}
orresizebox{<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{!}{.8height}{%
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}
If your
tabular
is just too tall, you can consider breaking it across the page boundary manually (that is, setting separatetabular
s to fit on each page). This may require the use of separate floats (and perhaps continued captions as well). However, there are packages that can assist with such automated breaking:longtable
,supertabular
andxtab
are a couple such packages. More packages are listed on CTAN. Also see How can I make a table that takes up more than a single page? or Make a table span multiple pages.
The following example is taken directly from the
longtable
documentation and illustrates the construction of thelongtable
environment components in order to break a table across multiple packages (with a "continued caption"):
documentclass{article}
usepackage{longtable}
defv{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 tablelabel{long}} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \
textsc{First} & textsc{Second} \
hlinehline
endfirsthead
caption{(continued)} \
hlinehline
multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \
textbf{First} & textbf{Second} \
hlinehline
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|'' & . \
hlinehline
That was ``verb|hlinehline|'' & . \
multicolumn{2}{||c||}%
{This is a ttfamilyv\multicolumnv{2v}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. \
hlinehline
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
Lotsfootnote{This is a footnote.} of lines & like this. \
Lots of lines & like thisfootnote{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).
edited Nov 25 at 1:50
answered Oct 6 '16 at 12:00
Werner
432k609521633
432k609521633
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text inc
/l
/r
columns, and the usual fix isp
/X
columns, so an example of that would be useful.
– Torbjørn T.
Oct 6 '16 at 12:09
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (GM
org.~m.
or alike) or an arbitrary symbol such as(dagger)
(†),(*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).
– boycott.se - yo'
Oct 6 '16 at 12:42
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
|
show 5 more comments
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text inc
/l
/r
columns, and the usual fix isp
/X
columns, so an example of that would be useful.
– Torbjørn T.
Oct 6 '16 at 12:09
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (GM
org.~m.
or alike) or an arbitrary symbol such as(dagger)
(†),(*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).
– boycott.se - yo'
Oct 6 '16 at 12:42
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
2
2
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text in
c
/l
/r
columns, and the usual fix is p
/X
columns, so an example of that would be useful.– Torbjørn T.
Oct 6 '16 at 12:09
I'm guessing you're not done here, but a common reason for having too wide tables is that the user has a lot of text in
c
/l
/r
columns, and the usual fix is p
/X
columns, so an example of that would be useful.– Torbjørn T.
Oct 6 '16 at 12:09
1
1
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
some publishers consider that table captions should go at the top (and figure captions at the bottom). other tactics not (yet) mentioned are that (1) if text in either a column heading or a cell is too wide, can be broken into multiple lines, using a "paragraph" approach to keep appropriate baselines, and (2) if material in a particular column has repetitive elements (such as a currency unit or"%"), that can be moved to the column header. great job!
– barbara beeton
Oct 6 '16 at 12:28
1
1
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (
GM
or g.~m.
or alike) or an arbitrary symbol such as (dagger)
(†), (*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).– boycott.se - yo'
Oct 6 '16 at 12:42
Another option: When it's only the column names that are long but not the values, you can create shorthands for the names: There are two basic options, for Geometric mean one could use the first letters (
GM
or g.~m.
or alike) or an arbitrary symbol such as (dagger)
(†), (*)
etc. Don't forget to add a legend in that case (in the caption or as a table footnote just below the last line of the table).– boycott.se - yo'
Oct 6 '16 at 12:42
3
3
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
Have you considered writing something for TUGboat based on this?
– Joseph Wright♦
Oct 26 '16 at 20:36
1
1
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
i second @JosephWright's suggestion. please do consider.
– barbara beeton
Oct 26 '16 at 20:58
|
show 5 more comments
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f332902%2fmy-table-doesnt-fit-what-are-my-options%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
We receive a large number of questions regarding tables that "don't fit". This is meant to be a resource to address those in a generic fashion.
– Werner
Oct 6 '16 at 12:01
5
If a table is too large, please consider first 1) should it be a table at all, and 2) does it really need all content you're stuffing into it? Changing the table's content is usually much more difficult than simply adjusting some typography, but it is frequently the better solution when you want to visualize information! You should be certain that your gigantic table is the best (or least bad) solution to convey information before you go on reading the answers here. (I'm posting this as a comment and not an answer, because it's not really TeX related).
– rumtscho
Oct 7 '16 at 11:25