Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

share|improve this question
1  
It's npt really a problem with subcaption, you can't expect every package to turn nag warnings on and off, nag is just a best guess checker, if you use it with packages it does not know about then some warnings will be wrong or warnings it could have made won't be made, that's just the way it is, if you know enough to patch commands to suppress the warnings, you probably don't need the nag package at all –  David Carlisle Aug 25 at 20:18
    
Why do use \phantomsubcaption at all? –  Christian Hupfer Aug 25 at 20:18
    
When I use 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 loading l2tabu? 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.) –  cfr Aug 25 at 21:41

2 Answers 2

up vote 3 down vote accepted

Make \phantomsubcaption known to nag:

\RequirePackage[l2tabu]{nag}
\makeatletter\g@addto@macro\nag@captions{,phantomsubcaption}\makeatother
\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 is the output I get on the terminal:

This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./phsc.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/nag/nag.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/nag/nag-l2tabu.cfg))
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption3.sty
(/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/keyval.sty)))
(/usr/local/texlive/2014/texmf-dist/tex/latex/caption/subcaption.sty)
(./phsc.aux)
No complaints by nag.
[1{/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./phsc.aux) )</usr/local/texlive/2014/texmf-dist/fonts/type1/public/amsfonts/c
m/cmr10.pfb>
Output written on phsc.pdf (1 page, 16851 bytes).
Transcript written on phsc.log.

enter image description here

share|improve this answer

You have a caption the reason why you should use \subcaption and not the phantom one:

\begin{figure}
\begin{minipage}[b]{.49\linewidth}
  \subcaption{First figure \label{lblA}}
\end{minipage}\hfill
\begin{minipage}[b]{.49\linewidth}
  \subcaption{Second figure \label{lblB}}
\end{minipage}
    \caption{A caption with subfigures \subref{lblA} and \subref{lblB}.}
\end{figure}

or use \subcaption* if you do not want a label:

\subcaption*{Second figure \phantomsubcaption\label{lblB}}
share|improve this answer
    
The usage of \phantomsubcaption by the OP is legitimate and follows the example at the end of section 6.3 in the manual of subcaption. –  egreg Aug 25 at 20:34
    
I didn't said that it is not "legitimate" ... –  Herbert Aug 25 at 20:45
    
But this is not an answer to the question. –  egreg Aug 25 at 20:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.