\phantom inside tabularx
Your row is defined as a \parbox
. The \parbox
always starts in vertical mode. This can be shown by the following example.
\documentclass{article}
\begin{document}
\parbox{8cm}{\ifvmode vmode \else hmode \fi}
\end{document}
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:
Simply saying
\hbox{...}
won’t work, since that box will just continue the previous vertical list without switching modes. You need to start the paragraph explicitly, and the straightforward way to do that is to say\indent\hbox{...}
. But suppose you want to define a macro that expands to anhbox
, where this macro is to be used in the midst of a paragraph as well as at the beginning; then you don’t want to force users to type\indent
before calling your macro at the beginning of a paragraph, nor do you want to say\indent
in the macro itself (since that might insert unwanted indentations). One solution to this more general problem is to say‘\␣\unskip\hbox{...}’
, since\␣
makes the mode horizontal while\unskip
removes the unwanted space. Plain TEX provides a\leavevmode
macro, which solves this problem in what is probably the most efficient way:\leavevmode
is an abbreviation for‘\unhbox\voidbox’
, where\voidbox
is a permanently empty box register.
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\parbox{8cm}{\ifvmode vmode \else hmode \fi}
\noindent\begin{tabularx}{\linewidth}{p{2.8cm} X}
1/00\,--\,2/00 & text text \\
\leavevmode\hphantom{0}1/00\,--\,2/00 & text text \\
01/00\,--\,2/00 & text text \\
10/00\,--\,11/00 & text text
\end{tabularx}
\end{document}
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
.
Marco has given the correct way to use \hphantom
in LaTeX but there shouldn't be any need to fake alignment with phantoms in an alignment structure like a tabular.
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{r@{\,--\,}lp{2.8cm} X}
1/00&2/00 & text text \\
1/00&2/00 & text text \\
01/00&2/00 & text text \\
10/00&11/00 & text text
\end{tabularx}
\end{document}