# Tabularx does not span the full width of the page

I want to create a table that spans the full width of the page and where one column is half of the size of another column. As suggested here, I use tabularx for that. For some reason, however, my table does not want to span the full page. In the MWE below, I gave the top row a color such that it is visualized that the cell width of the last column is not appropriate.

\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\newcolumntype{Y}{>{\hsize=0.5\hsize}X}  % Half the size of X.

\begin{document}

\begin{tabularx}{\linewidth}{XXY}  % E.g., XYY does work...
\hline
% The first row is given a color to clearly show the cell width.
\rowcolor{blue} A & B & Lorem ipsum dolor sit amet\\ \hline
a & b & c \\ \hline
\end{tabularx}

\end{document}


As one can see in the code, I use X for a normal column and Y for a column with half size. When I use columns XYY, it seems to work. Therefore, it seems pretty random to me. Could someone explain what is going wrong? What would be the correct way of creating columns the way I want (i.e., 40%, 40%, 20%)?

• your tabularx is in error even without the color, you need to make sure that the sum of the widths of X columns is 3\hsize see the tabularx manual Dec 6 '19 at 7:42
• you want 1.2\hsize 1.2\hsize 0.6\hsize Dec 6 '19 at 8:00
• Aahh, I see! Thanks a lot!
– EdG
Dec 6 '19 at 8:06

You simply misused the coefficients in\hsize=...: they are not really coefficients of proportionality, but barycentric coefficients, i.e. their sum has to be equal to the total number of X-type columns. In other words, here, you have to solve the linear system: 2x+y=3, x=2y.

Compare the result of your coefficients with the result of the correct coefficients. I added vertical rules to visualise the exact width of each column:

\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\newcolumntype{Y}{>{\hsize=0.5\hsize}X}  % Half the size of X.

\begin{document}

\begin{tabularx}{\linewidth}{XXY}  % E.g., XYY does work...
\hline
% The first row is given a color to clearly show the cell width.
\rowcolor{blue} A & B & Lorem ipsum dolor sit amet\\ \hline
a & b & c \\ \hline
\end{tabularx}

\end{document}


• You phrased my thoughts perfectly: I thought that the \hsize could be used as coefficients of proportionality. I was wrong :). Many thanks for pointing this out!
– EdG
Dec 6 '19 at 11:00
• You're welcome. You're not the unique case. That's why it is recommended to read carefully documentations (and ask if something is not quite clear) Dec 6 '19 at 11:03
• That is a good advice and it would have saved me (and you) quite a lot of time as it is clearly written in section 4.3. So it is not that the documentation is not clear (it is clear), but because I failed to read it.
– EdG
Dec 8 '19 at 0:15