When should the tabularx environment be used or not?

Is the tabularx environment useful?

Yes. But it's no environment intended to replace tabular with (i.e. it makes no sense to make every tabular a tabularx).

When should we use the tabularx environment?

You should use it when you need to calculate the width of a column with respect to a total width. Please note that if your columns are short and do not contain line breaks you do not gain anything from using tabularx. You can get fixed-width columns with regular p or wl specifiers.

Do you have any examples where this environment is useful?

  • When you need to reproduce word processor tables it's quite useful as they are often using equally-sized columns.
  • When you are going to have several columns which should be of equal-size and which will have line breaks.
  • When you are in a hurry and do not want to do calculations.

TeXnician already said when it's useful, I would like to add when it is detrimental.

Never use tabularx without an X column!

Sometimes I saw questions with this wrong usage here, never do that!

\documentclass{article} 
\usepackage{caption} 
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}  

\begin{document} 
\begin{table}\centering 
\caption{Here it is useful} 
\begin{tabularx}{\linewidth}{Xcc} 
\toprule
Column A & Column B & Column C \\ 
\midrule
\texttt{tabularx} is useful when there is one (or more) columns with long text which goes on more than one row & lions & ducks \\ 
\bottomrule
\end{tabularx}
\end{table}
\begin{table}\centering 
\caption{\label{tab:awful}Here it is useless and a bit awful (you only have short text in columns, there is too much blank space left)} 
\begin{tabularx}{\linewidth}{*3{>{\centering\arraybackslash}X}} 
\toprule
Column A & Column B & Column C \\ 
\midrule
marmots & lions & ducks \\ 
\bottomrule
\end{tabularx}
\end{table}
\begin{table}\centering 
\caption{\label{tab:wrong}Here it is detrimental and horrible (never use \texttt{tabularx} without an X column)} 
\begin{tabularx}{\linewidth}{ccc} 
\toprule
Column A & Column B & Column C \\ 
\midrule
marmots & lions & ducks \\ 
\bottomrule
\end{tabularx}
\end{table}
\begin{table}\centering 
\caption{Instead of Table \ref{tab:awful} or Table \ref{tab:wrong}, this one is much better} 
\begin{tabular}{ccc} 
\toprule
Column A & Column B & Column C \\ 
\midrule
marmots & lions & ducks \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here


The important thing to note about tabularx that it is all about automatically setting the target length for line breaking within a column. However the vast majority of data tables in scientific documents are (apart from the headings) tables of numerical data where there is no line breaking within the column, so I would say that tabularx is not suitable for those cases.

An X column is a p column of an automatically determined width, but like any p column it is a \parbox designed for paragraphs of text wrapped to the specified width.

Tags:

Tabularx