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}}}%
这种方法有危险吗? 有更好的方法吗?subcaption
v1.1-62 之后的版本是否已修复此问题?
编辑:如果我的 MWE 不清楚,请见谅。我之所以使用,是\phantomsubcaption
因为子标题标签 (a)、(b) 等都在图中。MWE 中的文本不是图的子标题,而是图本身的替代文本;我不想要子标题(因此\phantomsubcaption
)。
答案1
告知:\phantomsubcaption
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 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}}