[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#221822: \label has to be put after \caption in order to be effective



Martin Michlmayr <tbm@cyrius.com> schrieb:

> Package: tetex-bin
> Version: 2.0.2-5
> Severity: normal
>
> I have a table environment which I want to give a caption as well as a
> label so I can refer to it.  When I made a reference, I noticed that
> it was wrong -- instead of giving the number of the table the number
> of the section was given.  I tracked this down now and found out that
> you have to put the \caption _before_ the \label, otherwise the \label
> isn't effective.  I think this behaviour is wrong considering that my
> \label is clearly within \begin{table} and \end{table} and so it's
> obvious what the \label refers to.
>
> To show this problem I have attached files test1.tex and test2.tex.
> test1.tex refers to 2.1, which is wrong (it's the section), while
> test2.tex refers to 1, which is correct.

This problem is well known and it is impossible to fix, at least within
LaTeX2e (might be different with the yet-to-come LaTeX 3). A table (or
figure) environment need not have a \caption at all, and thus no
number. If one would do the stuff that is needed to "attach" a \label to
a figure or table environment, this would mean to give it a number. But
then, after

\begin{table}
\caption{...}
...
\end{table}
\begin{table}
...
\end{table}
\begin{table}
\caption{...}
...
\end{table}

the second caption would be "Table 3: ..." and everybody would wonder
where ist Table 2?

> This behaviour is very unintuitive and I hope this can be fixed
> upstream.

See it the other way, then it's not so counterintuitive: What you want
to label ist not the floating environment (the commands "please let the
following appear where appropriate, perhaps not exactly here"), but it
is the tabular, or the picture in a figure environment, together with
its description, the caption. Then it's clear that \label has to come
after that.

Also, if the \label location would be connected with the environment
instead of \caption, than packges like captof.sty wouldn't work, which
make it possible to have a \caption and listof... entry for non-floating
stuff. 

As you can see, changing this behavior is impossible without breaking a
lot of other things. Maybe it is possible in LaTeX 3, because then
incompatibilities are inevitable. If you would like to discuss this with
the LaTeX 3 team, you can do this. But please note that, since there
will be fundamental differences, you should check whether your problem
still exists there. The Debian tetex maintainers won't have time to do
delve into the depth of LaTeX 3 development (and no will, too, most
probably). 

If you can accept that, it would be nice if you close this bug. Simply
send mail to 221822-done@bugs.debian.org.

Thank you, Frank
-- 
Frank Küster, Biozentrum der Univ. Basel
Abt. Biophysikalische Chemie




Reply to: