Disclaimer: Although tabu
might still work in cases it’s development is kind of stuck and it is better to not use it (for new documents). See also Is the tabu package obsolete?
One can use tabu
(e.g). It will set the table to a given width without needing to calc the ration by hand.
\documentclass{article}
\usepackage{tabu}
\usepackage{booktabs}% for better rules in the table
\begin{document}
\begin{tabu} to \textwidth {XXXX}
\toprule
xx & 1 & 2 & 3 \\
\bottomrule
\end{tabu}
\end{document}
tabu
comes with the new column type X
which sets its width automatically. It has an optional argument taking l
, r
, c
to adjust the alignment inside the cell or a numer to set uneven widths of columns. For example two columns, the first on right, the second one left aligned and twice the width of the first one, will be X[r]X[2]
(l
and 1
will be set by default). The part between to
and {<cols>}
can be any width, and the full part can be omitted to, i.e. \begin{tabu}{<cols>}
.
tabu
is compatible with longtable
with the new environment {longtabu}
.
Adding showframe
and some text (lipsum
) to the above example shows that the table has exactly the width of the text. On may notice that a table without a float environment is set inline and gets indented as every normal text, too. Use \noindent
to prevent that.

\documentclass{article}
\usepackage{tabu}
\usepackage{booktabs}% for better rules in the table
\usepackage{showframe,lipsum}
\begin{document}
\lipsum[4]
\noindent
\begin{tabu} to \textwidth {XXXX}
\toprule
xx & 1 & 2 & 3 \\
\bottomrule
\end{tabu}
\end{document}
{\bf <text>}
but\textbf{<text>}
or\bfseries
instead! Same is true for\it
and\tt
or how they are called. They are all deprecated. Please see the l2tabu document for this and other things.