nag [l2tabu] 和 \phantomsubcaption

nag [l2tabu] 和 \phantomsubcaption

nag与选项一起使用的包会l2tabu抱怨当\label在浮点数中使用 而没有跟在 之后时\caption。不幸的是,它不明白包\phantomsubcaption中的subcaption应该被计算在内。一个例子:

\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}

这引发了以下形式的投诉

包 nag 警告:\label 在浮点数中,但不在输入行 7 上的 \caption 之后。

答案nag之前关于和的问题subcaption在这种情况下也可以使用;重新声明\phantomsubcaption和添加\@nameuse{nag@hascaptiontrue}可以解决问题:

\renewcommand*\phantomsubcaption{%
  \caption@iftype
    {\setcaptionsubtype*\phantomcaption\@nameuse{nag@hascaptiontrue}}%
    {\caption@Error{\noexpand\phantomsubcaption outside float}}}%

这种方法有危险吗? 有更好的方法吗?subcaptionv1.1-62 之后的版本是否已修复此问题?

编辑:如果我的 MWE 不清楚,请见谅。我之所以使用,是\phantomsubcaption因为子标题标签 (a)、(b) 等都在图中。MWE 中的文本不是图的子标题,而是图本身的替代文本;我不想要子标题(因此\phantomsubcaption)。

答案1

告知:\phantomsubcaptionnag

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

在此处输入图片描述

答案2

您有一个标题,说明了为什么您应该使用它\subcaption而不是幻影:

\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}

\subcaption*如果您不想要标签,请使用:

\subcaption*{Second figure \phantomsubcaption\label{lblB}}

相关内容