[Tex/LaTex] latex how to make table as the same width as the textwidth

tableswidth

I have used \begin{tabularx} or \begin{tabular*} but neither of these two work, these two environment managed to increase the width of the table as the same as the text, while they cannot let the column contents inside the table increased associated with the table width.

Best Answer

The tabular* environment is able only to act on the intercolumn space, while tabularx can decide the width of the columns via the column specifier X. If one uses the latter environment without X columns, no automatic enlargement will happen.

Suppose you have three columns, with the first listing the items, the second with descriptions and the third with comments; we want that the latter two enlarge proportionally to the desired table width

\usepackage{tabularx,booktabs}
...

\begin{tabularx}{\textwidth}{l X X}
\toprule
Item & Description & Comments \\
\midrule
Item 1 & 
  this is the description of item 1 &
  these are the comments on item 1 \\
Item 2 & 
  this is the description of item 2 &
  these are the comments on item 2 \\
...
\bottomrule
\end{tabularx}

(I've used the rules provided by the booktabs package). Put the environment inside a table environment with \centering and you're done. It's also possible to have X columns of different width, a method is explained in the manual of tabularx. There's also the tabu package, that should be able to manage this kind of tables.

Related Question