I tried to improve the alignment in the following table using a \hphantom
:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\linewidth}{p{2.8cm} X}
1/00\,--\,2/00 & text text \\
\hphantom{0}1/00\,--\,2/00 & text text \\
01/00\,--\,2/00 & text text \\
10/00\,--\,11/00 & text text
\end{tabularx}
\end{document}
but somehow this adds a lineskip in the cell containing the \hphantom
:
Being fully aware that the error is on my side, and not in the tabularx
package, my two questions are:
-
Can I make the
\hphantom
work somehow inside the thetabularx
? -
Even without the offending row containing the
\hphantom
I get anOverfull \hbox (15.0pt too wide)
, which should not be there. What can I do to get rid of this warning?
Best Answer
Your row is defined as a
\parbox
. The\parbox
always starts in vertical mode. This can be shown by the following example.That means a simple next box will continue the previous vertical list without switching modes. You need to start the paragraph explicitly in horizontal mode to use a box e.g.
\hphantom
. This is explained in the previous answer Function and usage of \leavevmode. More information are given in the TeX Book:As mentioned by Werner: Use \noindent before you start the tabularx. The 15pt is the regular paragraph indent that tabularx is pushed to the right. This avoids the
15pt overfull \hbox
.