\subcaptionphantom
当子图在单个图上进行标记时很好,但是subcaption
今天回忆录家里不允许使用这种包裹。
于是制定了一个解决方案:
然而,这在图周围留下了大量的空白:
\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{duckuments}
\newsubfloat{figure}
% =============== defining the \subcaptionphantom ===================================
\makeatletter
% \begin{macro}{\subcaptionphantom}
% \cs{subcaptionphantom}\oarg{list-entry}\marg{caption} is a hidden
% non-printed subcaption. Designed for the case if "(a)", "(b)" are
% already embedded in the figure itself.
% Roughtly equivalent to \cs{phantomsubcaption} from the \Lpack{subcaption} package.
%
% \begin{macrocode}
\newcommand{\subcaptionphantom}{%
\bgroup
\let\label=\memsub@label
\ifdonemaincaption\else
\advance\csname c@\@captype\endcsname\@ne
\fi
\refstepcounter{sub\@captype}\@contkeep
\@ifnextchar [%
{\@memsubcapphantom{sub\@captype}}%
{\@memsubcapphantom{sub\@captype}[\@empty]}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\@memsubcapphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcap}, adapted
% for use in \cs{subcaptionphantom}.
% \begin{macrocode}
\long\def\@memsubcapphantom#1[#2]#3{%
\@tempdima=\hsize
\vskip\subfloatcapskip
\ifx \@empty #2
\@memsubcaptionphantom{#1}{#3}{#3}%
\else
\@memsubcaptionphantom{#1}{#2}{#3}%
\fi
\vskip\subfloatcapskip
\egroup}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@memsubcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcaption}, adapted
% for use in \cs{memsubcapphantom}.
% \begin{macrocode}
\newcommand{\@memsubcaptionphantom}[3]{%
\ifx \relax#2\relax \else
\bgroup
\let\label\@gobble
\let\protect\string
\def\@memsubcaplabel{\@nameuse{@@the#1}}%
\xdef\@memsubfigcaptionlist{%
\@memsubfigcaptionlist,%
{\protect\numberline{\@memsubcaplabel}\noexpand{\ignorespaces #2}}}%
\egroup
\fi
\@makesubfloatcaptionphantom{\@nameuse{@the#1}}{#3}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\@makesubfloatcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{makesubfloatcaption}, adapted
% for use in \cs{memsubcaptionphantom}.
% \begin{macrocode}
\newcommand{\@makesubfloatcaptionphantom}[2]{%
\setbox\@tempboxa\hbox{%
\@subcapsize
{\phantom{\@subcaplabelfont#1}}{\ignorespaces #2}\unskip}%
\@tempdimb=-\subfloatcapmargin
\multiply\@tempdimb\tw@
\advance\@tempdimb\@tempdima
\hb@xt@\@tempdima{%
\hss
\ifdim \wd\@tempboxa >\@tempdimb
\phantom{\memsubfig@caption{#1}}{#2}%
\else
\if@shortsubcap
\phantom{\memsubfig@caption{#1}}{#2}%
\else
\box\@tempboxa
\fi
\fi
\hss}}
% \end{macrocode}
% \end{macro}
\makeatother
\begin{document}
\chapter{duck}
\lipsum[1-4]
\begin{figure}[h]
\centering
% \vspace{-4cm}
\subcaptionphantom{\label{a}}~%
\subcaptionphantom{\label{b}}~%
\subcaptionphantom{\label{c}}~%
\subcaptionphantom{\label{d}}~%
\subcaptionphantom{\label{f}}~%
\subcaptionphantom{\label{g}}~%
\includegraphics{example-image-duck}
\caption{Some figures.
A figure named \subcaptionref{a}.
A figure named \subcaptionref{b}.
A figure named \subcaptionref{c}.
A figure named \subcaptionref{d}.
A figure named \subcaptionref{f}.
A figure named \subcaptionref{g}.
}
\label{duck}
\end{figure}
\lipsum[5-10]
\end{document}
到目前为止,我的解决方案是注释掉,\vspace{-4cm}
但这不精确也不切实际。有没有更好的方法来删除空格
答案1
这似乎有效
- 删除
\@memsubcapphantom
跳过并添加\leavevmode
- 使
\@makesubfloatcaptionphantom
框宽度为零,而不是\@tempdima
可能还有更好的方法。
代码:
\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{duckuments}
\newsubfloat{figure}
% =============== defining the \subcaptionphantom ===================================
\makeatletter
% \begin{macro}{\subcaptionphantom}
% \cs{subcaptionphantom}\oarg{list-entry}\marg{caption} is a hidden
% non-printed subcaption. Designed for the case if "(a)", "(b)" are
% already embedded in the figure itself.
% Roughtly equivalent to \cs{phantomsubcaption} from the \Lpack{subcaption} package.
%
% \begin{macrocode}
\newcommand{\subcaptionphantom}{%
\bgroup%
\let\label=\memsub@label%
\ifdonemaincaption\else%
\advance\csname c@\@captype\endcsname\@ne%
\fi%
\refstepcounter{sub\@captype}\@contkeep%
\@ifnextchar[%
{\@memsubcapphantom{sub\@captype}}%
{\@memsubcapphantom{sub\@captype}[\@empty]}}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\@memsubcapphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcap}, adapted
% for use in \cs{subcaptionphantom}.
% \begin{macrocode}
\long\def\@memsubcapphantom#1[#2]#3{%
\@tempdima=\hsize%
% \vskip\subfloatcapskip % <- removed
\ifx\@empty#2%
\leavevmode% <- added
\@memsubcaptionphantom{#1}{#3}{#3}%
\else%
\leavevmode% <- added
\@memsubcaptionphantom{#1}{#2}{#3}%
\fi%
% \vskip\subfloatcapskip % <- removed
\egroup}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@memsubcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcaption}, adapted
% for use in \cs{memsubcapphantom}.
% \begin{macrocode}
\newcommand{\@memsubcaptionphantom}[3]{%
\ifx\relax#2\relax\else%
\bgroup%
\let\label\@gobble%
\let\protect\string%
\def\@memsubcaplabel{\@nameuse{@@the#1}}%
\xdef\@memsubfigcaptionlist{%
\@memsubfigcaptionlist,%
{\protect\numberline{\@memsubcaplabel}\noexpand{\ignorespaces #2}}}%
\egroup%
\fi%
\@makesubfloatcaptionphantom{\@nameuse{@the#1}}{#3}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\@makesubfloatcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{makesubfloatcaption}, adapted
% for use in \cs{memsubcaptionphantom}.
% \begin{macrocode}
\newcommand{\@makesubfloatcaptionphantom}[2]{%
\setbox\@tempboxa\hbox{%
\@subcapsize%
{\vphantom{\@subcaplabelfont#1}}{\ignorespaces #2}\unskip}%
\@tempdimb=-\subfloatcapmargin%
\multiply\@tempdimb\tw@%
\advance\@tempdimb\@tempdima%
%\hb@xt@\@tempdima{% % <- changed
\hb@xt@ 0pt{%
\hss%
\ifdim \wd\@tempboxa >\@tempdimb%
\vphantom{\memsubfig@caption{#1}}{#2}%
\else%
\if@shortsubcap%
\vphantom{\memsubfig@caption{#1}}{#2}%
\else%
\box\@tempboxa%
\fi%
\fi%
\hss}}
% \end{macrocode}
% \end{macro}
\makeatother
\begin{document}
\chapter{duck}
\lipsum[1-4]
\begin{figure}[h]
\centering
% \vspace{-4cm}
\def\LABELS{%
\subcaptionphantom{\label{a}}%
\subcaptionphantom{\label{b}}%
\subcaptionphantom{\label{c}}%
\subcaptionphantom{\label{d}}%
\subcaptionphantom{\label{f}}%
\subcaptionphantom{\label{g}}}%
\LABELS%
\includegraphics{example-image-duck}
\caption{Some figures.
A figure named \subcaptionref{a}.
A figure named \subcaptionref{b}.
A figure named \subcaptionref{c}.
A figure named \subcaptionref{d}.
A figure named \subcaptionref{f}.
A figure named \subcaptionref{g}.
}
\label{duck}
\end{figure}
\lipsum[5-10]
\end{document}
答案2
您可以使用\baselineskip
来获取行高。
这可以插入到 中\vspace
。因此,您可以使用\vspace{-n\baselineskip}
其中存在的命令n
数。\subcaptionphantom{}
这个解决方案还不够完善,因为它不是自动的。