0

The following minimal example doesn't do what I expect:

\documentclass{article}
\begin{document}
\begin{tabular}{p{40mm}p{60mm}}\label{blah}
a & b \\
c & d
\end{tabular}
\end{document}

The output looks like this:

enter image description here

I don't understand why the b is displaced upward. If I remove the label, the problem goes away. Can anyone explain?

9
  • 1
    Try removing the label. Anyway, there's no table environment, hence no table counter.
    – Bernard
    Apr 22, 2020 at 19:24
  • 2
    ...we've had this before somewhere...
    – Werner
    Apr 22, 2020 at 19:35
  • 2
    @BenCrowell - For \label to work, LaTeX has to be able to associate the argument of \label with a counter. The \caption command, when used inside a table (not tabular) environment, increments a counter called table. If you place \label after \caption, LaTeX will make the correct connection. In contrast, your particular use of \label is guaranteed to achieve nothing useful -- and, in fact, mess things up in unexpected ways. Interestingly, if one embeds your tabular environment (sans the \label directive) inside a table environment, the problem vanishes.
    – Mico
    Apr 22, 2020 at 19:56
  • 1
  • 1
    @Mico it is definitely not a bug more a documented feature (you see the same with other things, notably \color) and so long as you don't need \ref it's Ok to use \label here. By design it does something more or less sensible even if no counter is active. Apr 22, 2020 at 23:20

1 Answer 1

2

You need to put the \label somewhere safer:

enter image description here

\documentclass{article}
\begin{document}

\hrule

\begin{tabular}{p{40mm}p{60mm}}\label{blah}
a & b \\
c & d
\end{tabular}


\hrule

\begin{tabular}{p{40mm}p{60mm}}
a\label{blah2} & b \\
c & d
\end{tabular}

\hrule

\begin{tabular}{p{40mm}p{60mm}}
a & b \\
c & d
\end{tabular}\label{blah3}

\hrule

\end{document}

A \label is not like \typeout that simply writes to the terminal it has to delay the writing to the aux file until the page number is known. The resulting write node is in many ways like a box of height and width 0pt and that is the effect that you see on the layout: the parbox (vtop) is aligning on the first node in its vertical list which is the invisible write node.

You must log in to answer this question.