Tx · LaTeX & TikZ

How to Set the Width of a LaTeX Tabular

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose the width

    Use the current line width for a column-sized table, especially inside multicol.

  2. 2. Pick the table type

    Use tabularx to wrap text, or tabular* to stretch the gaps between columns.

  3. 3. Check the result

    Keep the table within the available width; scaling is a fallback, not the first choice.

A standard tabular has no target-width argument. With natural-width columns, its width is determined by the contents and spacing; specified-width columns such as p{...} also affect it. To control the overall width, choose an environment that matches what you want the table to do: wrap text in columns with tabularx, or stretch the gaps between columns with tabular*.

In a multicol column, the available width is the width of that column, not the full page. \linewidth is usually the right width to use because it tracks the current line width.

Use tabularx to wrap text

The tabularx package provides an X column type. It calculates that column’s width so the table reaches the requested width, and wraps text in the column as needed. This is usually the best choice when a table must fit a column and has text-heavy cells.

Here is a complete example using a table inside a two-column multicols environment. It needs the multicol and tabularx packages:

\documentclass{article}
\usepackage{multicol}
\usepackage{tabularx}

\begin{document}
\begin{multicols}{2}

Text in the first column. The table below is sized to the width
available in this column.

\noindent
\begin{tabularx}{\linewidth}{@{}lXr@{}}
\hline
Item & Description & Cost \\
\hline
A & A longer description that wraps within the available space. & 12.50 \\
B & A shorter description. & 8.00 \\
\hline
\end{tabularx}

Text continues in the two-column layout.

\end{multicols}
\end{document}

The first argument of tabularx is the target width. Here, \linewidth means the current column’s line width. The X in the column specification takes the remaining width and wraps its text; l and r make the other columns natural-width, left- and right-aligned columns. The outer @{} entries remove the table’s usual padding at its left and right edges. Remove them if you want that padding.

If you use more than one X column, tabularx shares the available width among them. It does not automatically make every column the same width as every other column type.

Use tabular* to stretch column gaps

If the cell contents already fit on one line and you only want the table to occupy a specified width, use tabular* with stretchable intercolumn space:

\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}lcr}
\hline
Left & Center & Right \\
\hline
A & B & C \\
\hline
\end{tabular*}

The first argument sets the target width. \extracolsep{\fill} adds stretchable space between columns so the table expands to that width. Unlike tabularx, tabular* does not wrap cell contents to make them fit. If the natural table is wider than the target, it can still overrun the available space.

Set widths for specific columns

You can also use p{<width>} in an ordinary tabular to give a column a fixed width and allow its text to wrap. For example, p{4cm} creates a paragraph column four centimetres wide. This controls that column, not the table’s total width; the other columns and the spacing between them still contribute to the overall size.

Common mistakes

  • Using \textwidth inside a narrow column. \textwidth is the document’s text-block width, while a multicol column is narrower. A table set to \textwidth may overflow. Use \linewidth for the current line width.
  • Expecting tabular to stretch automatically. A normal tabular has no target-width setting. Choose tabularx or tabular* when you need a specified overall width.
  • Making the target smaller than the contents. A target width or stretchable spacing cannot make long unbreakable entries fit. For text with ordinary break points, allow wrapping with X or p{...}; for unbreakable entries, shorten them or provide break opportunities, or adjust the layout.
  • Scaling as the first fix. \resizebox{\linewidth}{!}{...} from graphicx can shrink a table, but it shrinks the text and rules too. Use it only when wrapping or revising the columns will not work.

For a text-heavy table in a multicolumn layout, start with tabularx and \linewidth. For short entries that should stay on one line, use tabular* if you want the column spacing to fill the width.

References

  1. tabularx — CTAN package page
  2. LaTeX2e unofficial reference manual: tabular

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.