The nag
package used with the l2tabu
option complains when \label
is used in a float without following a \caption
. Unfortunately, it does not understand that a \phantomsubcaption
, from the subcaption
package, should count. An example:
\RequirePackage[l2tabu]{nag}
\documentclass{article}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}
{\fbox{(a) FIGURE} \phantomsubcaption\label{lblA}}
\hfill
{\fbox{(b) OTHER FIGURE} \phantomsubcaption\label{lblB}}
\caption{A caption with subfigures \subref{lblA} and \subref{lblB}.}
\end{figure}
\end{document}
This generates complaints of the form
Package nag Warning: \label in float, but not after \caption on input line 7.
The answer to a previous question about nag
and subcaption
can be used in this case too; redeclaring \phantomsubcaption
and adding \@nameuse{nag@hascaptiontrue}
fixes up the problems:
\renewcommand*\phantomsubcaption{%
\caption@iftype
{\setcaptionsubtype*\phantomcaption\@nameuse{nag@hascaptiontrue}}%
{\caption@Error{\noexpand\phantomsubcaption outside float}}}%
Are there dangers in this approach? Is there a better way? Does a later version of subcaption
than v1.1-62 have this fixed?
EDIT: Sorry if my MWE was unclear. I'm using \phantomsubcaption
because the subcaption labels, (a), (b), and so on, are in the figures themselves. The text in the MWE is not the subcaption of the figure, but a standin for the figure itself; I want no subcaption (hence \phantomsubcaption
).
\phantomsubcaption
at all?l2tabu
, I tend to compile with it, examine the warnings and then go through them fixing or discarding as applicable. Then I remove the package from my document. I see it as a checker which can give useful, but hardly infallible, information. Once you've decided the warnings are spurious, why keep loadingl2tabu
? I don't understand why you'd use this standardly rather than a diagnostic when needed. (I don't use it very much, though, to be honest. So maybe I just don't get its purpose.)