When I posted this, I did not realise that Mico had posted an answer
using tabularx
3 minutes
earlier than I hit the submit
button. So credit for the use of
tabularx should go to Mico.
I am leaving this answer, with Mico's approval, because it also
demonstrates the advantages of using
booktabs to create nicer horizontal
rules and dispensing with vertical rules. This enables you to produce
professional quality tables. For more information, take a look at the
booktabs
manual
which provides lots of advice about presenting information effectively
in tabulars. (The manual is also available in
French
and
German.)
For completeness, here is a solution which combines tabularx
with booktabs
.
As Mico explains, tabularx
allows you to specify the total width of the table. At least one of your columns must then be X
which expands to fill the width. In this case, I use array
to define a centred version of this column type, C
and specify 3 such columns for the table.
booktabs
provides enhanced spacing and additional commands for drawing horizontal rules. In a professional quality table, the top and bottom rules should be heavier than rules within the table. Consequently, booktabs
provides \toprule
, \midrule
and \bottomrule
as demonstrated below. For additional possibilities, including \cmidrule
and rule trimming, see the excellent package documentation.
\documentclass{article}
\usepackage{array,booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tabularx}{\linewidth}{*{3}{C}}
\toprule
Header 1 & Header 2 & Header 3\\\midrule
This is some text which will be longer than the width of the column. & This is some more text which will be longer than the width of this second column. & And here is some more text for the third column.\\\bottomrule
\end{tabularx}
\end{document}
