You can either fix the column width by specifying a paragraph style p{<len>}
, or you can use a different tabular environment that stretches according to the contents up to the maximum width of the text block. The latter is provided by the tabularx
package which defines the environment tabularx
with an additional width-of-table argument, as well as the stretchable X
column specifier.
An example of the first suggestion:
\documentclass[12pt]{report}
\usepackage[a4paper,left=15mm,right=15mm, top=1cm, bottom=2cm]{geometry}% http://ctan.org/pkg/geometry
\begin{document}
\noindent\begin{tabular}{|l|c|p{0.7\linewidth}|}
\hline
a & b & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\\
\hline
\end{tabular}
\end{document}
An example of the second suggestion:
\documentclass[12pt]{report}
\usepackage[a4paper,left=15mm,right=15mm, top=1cm, bottom=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\noindent\begin{tabularx}{\linewidth}{|l|c|X|}
\hline
a & b & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\\
\hline
\end{tabularx}
\end{document}
The tabularx
approach is an easy way out since you don't have to worry about specifying a column width that exactly matches the remaining column space on the page. However, it is possible to calculate the appropriate value of <len>
when using the p{<len>}
column specifier.
In response to part 2 of the user's question:
\documentclass{article}
\usepackage{graphicx}
\parindent 0in\parskip 1ex
\begin{document}
Textwidth:\\
\rule{\textwidth}{0.3ex}\par
First, let's create an oversized table:\par
\def\x{%
\begin{tabular}{|p{2in}|p{2in}|p{1.5in}|}
\hline
First column & Second column & Third Column \\
\hline
\end{tabular}
}
\x\par
Now I will scale the table to 79 percent of original\par
\scalebox{.79}{\x}
\end{document}
Best Answer
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 atabular
. Working with the latter - atabular
- and how to adjust it is what is discussed here. The discussion also applies toarray
structures since they provide a math analogue totabular
.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 atabular
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):
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).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:Justified wrapping within the
X
-columns may cause overfull\hbox
warnings, which may be avoided by using a\raggedright
setting. Sincetabularx
loadsarray
, column prefixes>{<prefix>}
can be added.tabulary
provides a similar interface and may also be helpful in this regard.Rotational formatting is fairly extreme visually and should be used sparingly.
tabular
is smaller, width-fittingtabular
s. It's the least invasive visually (in general) and perhaps airs out the information for better reader digestion: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?.\tabcolsep
to be6pt
. Forarray
s the length used is\arraycolsep
with a default of5pt
. This may be more than you need. For a multi-columntabular
, reducing the\tabcolsep
could save you valuable points.It may be required to limit the scope of the change to
\tabcolsep
, hence the use of grouping the\setlength
adjustment (via\begingroup
...\endgroup
or{
...}
).tabular
. If using the default\normalsize
for your document, perhaps\small
or\footnotesize
might make it fit: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{
...}
).tabular
s, you can resize the entire table to fit within your bounds horizontally using\resizebox{<width>}{<height>}{<tabular>}
where<width>
is at most\linewidth
or\textwidth
(see Difference between \textwidth, \linewidth and \hsize). The notation!
for<height>
will ensure that the aspect ratio of the resizing is kept.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
.tabular
can butt into the margin(s) because any of the above changes are just not sufficient for your needs. However, the default\centering
doesn't set thetabular
in a centred way, so you can set thetabular
inside a\makebox[<width>]
of small enough<width>
(less than\linewidth
) which will automatically centre it within the margin span (see How can I center a too wide table?):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:graphicx
's\rotatebox{<angle>}{<tabular>}
is used to rotate the<tabular>
by<angle>
degrees.The above example rotates the
tabular
only, leaving the caption in its original place. If you want to rotate the entire float - caption included, you can use asidewaystable
(provided by therotating
package):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 multipletabular
s; some suggestions are listed below.\arraystretch
is used to stretch (or shrink) each row within atabular
. Perhaps your\documentclass
increased this. You can adjust it using\renewcommand
:tabular
:Again, here, scoping might be required to limit font changes.
graphicx
's\scalebox{<factor>}
or\resizebox{<width>}{<height>}
is an option. You can specify an appropriate height-fitting<height>
length or portion. A<width>
of!
ensures to maintain the aspect ratio during resizing: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
,ltxtable
,xltabular
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 pages (with a "continued caption"):###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).