Table: Strange half-column

The following lines in latex:

\begin{table}[H]
\begin{tabularx}{\textwidth}{|l|l|l|l|r|}
\hline
& Cat 1 & Cat 2 & Cat 3 & Cat 4 \\ \hline
Dimension 1 & 49.9 $\mu$m & 52.57 $\mu$m & 53.1 $\mu$m & 124.89$\mu$m \\
Dimension 2 & 48.89 $\mu$m & 45.49 $\mu$m & 45.8 $\mu$m&  86.4318$\mu$m \\
Dimension 3 & 50.55 $\mu$m & 68.2 $\mu$m& 64.1 $\mu$m& 210.5501$\mu$m \\
Dimension 4 & 15.99 $\mu$m & 23.3 $\mu$m& 23.3 $\mu$m& 54.51$\mu$m \\
Dimension 5 & 41.04 $\mu$m & 36.1$\mu$m & 36.2 $\mu$m& 78.99 $\mu$m \\

\hline
\end{tabularx}
\caption{test }
\label{t:stats}
\end{table}


create next to the table a weird semi-column to the right:

why is that?

• please always post a complete document taht can be tested, not a fragment, but a tabularx environment must have at least one X column. Commented Mar 8, 2018 at 19:57

2 Answers

Using tabularx with {\textwidth} creates a table which is the width of the text. The 4 left aligned columns, and 1 right aligned are of the width of their widest entry in their column. This means that there is still space left to the right - hence the half column. If you instead use

\begin{tabularx}{\textwidth}{|X|l|l|l|r|}


Then the first column will now have a width such that the entire table has the width of the text.

A full MWE (minimum working example) that implements this suggestion:

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|X|l|l|l|r|}
\hline
& Cat 1 & Cat 2 & Cat 3 & Cat 4 \\ \hline
Dimension 1 & 49.9 $\mu$m & 52.57 $\mu$m & 53.1 $\mu$m & 124.89$\mu$m \\
Dimension 2 & 48.89 $\mu$m & 45.49 $\mu$m & 45.8 $\mu$m&  86.4318$\mu$m \\
Dimension 3 & 50.55 $\mu$m & 68.2 $\mu$m& 64.1 $\mu$m& 210.5501$\mu$m \\
Dimension 4 & 15.99 $\mu$m & 23.3 $\mu$m& 23.3 $\mu$m& 54.51$\mu$m \\
Dimension 5 & 41.04 $\mu$m & 36.1$\mu$m & 36.2 $\mu$m& 78.99 $\mu$m \\
\hline
\end{tabularx}
\caption{test }
\label{t:stats}
\end{table}
\end{document}

• What a nice/simple solution. Thank you! Commented Mar 8, 2018 at 20:40
• I've taken the liberty of posting some compilable code and a screenshot that implements your suggestion. Feel free to revert or modify as you see fit.
– Mico
Commented Mar 8, 2018 at 21:09

Using a tabularx environment for the table at hand seems like overkill, especially because there's no need for automatic line-breaking within cells. I'd like to suggest that you (a) use a tabular* environment instead, (b) align the numbers on their decimal markers (using the S column type provided by the siunitx package), (c) declutter the table by moving the information about the unit of measurement into the header cells, and (d) give the table a much more open "look" by removing all vertical lines and employing well-spaced horizontal lines (courtesy of the macros of the booktabs package).

% !TEX TS-program = pdflatex
\documentclass{article}
\usepackage{siunitx,booktabs}

\begin{document}
\begin{table}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
l S[table-format=2.2] S[table-format=2.2]
S[table-format=2.1] S[table-format=3.4]}
\toprule
& {Cat 1} & {Cat 2} & {Cat 3} & {Cat 4} \\
& {(\si{\micro\meter})} & {(\si{\micro\meter})}
& {(\si{\micro\meter})} & {(\si{\micro\meter})} \\
\midrule
Dimension 1 & 49.9  & 52.57 & 53.1 & 124.89   \\
Dimension 2 & 48.89 & 45.49 & 45.8 &  86.4318 \\
Dimension 3 & 50.55 & 68.2  & 64.1 & 210.5501 \\
Dimension 4 & 15.99 & 23.3  & 23.3 &  54.51   \\
Dimension 5 & 41.04 & 36.1  & 36.2 &  78.99   \\
\bottomrule
\end{tabular*}
\caption{test}
\label{t:stats}
\end{table}
\end{document}