我有类似的问题如何更改图形列表中子图的显示?。
我正在使用该subcaption
包。我不需要显示所有图形的标题,但对于一些有子图的图形,我只想显示子图的标题。我该如何实现?
所以我想从目前的情况来看:
2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
a Subcaption 1 . . . . . . . . . . . . . . . . . . . . . . . . . 6
b Subcaption 2 . . . . . . . . . . . . . . . . . . . . . . . . . 6
使其显示如下:
2.1 a Subcaption 1 . . . . . . . . . . . . . . . . . . . . . . . . . 6
b Subcaption 2 . . . . . . . . . . . . . . . . . . . . . . . . . 6
代码如下:
\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[list=true]{subcaption}
\begin{document}
\begin{figure}[H]
\begin{subfigure}{\textwidth}
\includegraphics[width=textwidth]{subfigure1.jpg}
\caption{subcaption 1}
\end{subfigure}%
\begin{subfigure}{\textwidth}
\includegraphics[width=\textwidth]{subfigure2.jpg}
\caption{subcaption 2}
\end{subfigure}
\caption[~]{Caption}
\end{figure}
\end{document}
答案1
要使此操作有效,您不能在图形中使用 \caption。在另一个图形中,可以。但这个不行。
\firstsubcaption 将图形编号放入 lof,而 \nextsubcaption 仅将子图形放入 lof。 \dummycaption 看起来像图形标题,但除此之外什么也不做。
这些标题的格式不太灵活,但它们会居中,直到达到 \textwidth,然后切换到悬挂缩进。您可以随意使用 \makecaption,直到您满意为止。
\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{caption}% not needed, but compatible
\usepackage[list=true]{subcaption}% not needed, but compatible
\usepackage{mwe}
\makeatletter
\@ifundefined{c@subfigure}{%
\newcounter{subfigure}[figure]%
\renewcommand{\thesubfigure}{\alph{subfigure}}%
}{}%
\makeatother
\newlength{\tempwidth}
\newsavebox{\tempbox}
\newcommand{\makecaption}[2]% #1 = caption head, #2 = caption text
{\savebox{\tempbox}{#1#2}%
\ifdim\wd\tempbox>\textwidth
\settowidth{\tempwidth}{#1}%
\savebox{\tempbox}{\parbox{\textwidth}%
{\hangindent=\tempwidth
\hangafter=1
\makebox[\tempwidth][l]{#1}#2}}%
\fi
\vskip\abovecaptionskip
{\centering\usebox{\tempbox}\par}%
\vskip\belowcaptionskip\hbox{}}
\newcommand{\firstsubcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\refstepcounter{figure}%
\refstepcounter{subfigure}%
\ifx#1\empty
\addcontentsline{lof}{figure}{\string\numberline {\thefigure}{\hbox to .5in{\thesubfigure}\ignorespaces #2 \relax}}%
\else
\addcontentsline{lof}{figure}{\string\numberline {\thefigure}{\hbox to .5in{\thesubfigure}\ignorespaces #1 \relax}}%
\fi
\makecaption{(\thesubfigure) }{#2}}
\newcommand{\nextsubcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\refstepcounter{subfigure}%
\ifx#1\empty
\addcontentsline{lof}{figure}{\string\numberline { }{\hbox to .5in{\thesubfigure}\ignorespaces #2 \relax}}%
\else
\addcontentsline{lof}{figure}{\string\numberline { }{\hbox to .5in{\thesubfigure}\ignorespaces #1 \relax}}%
\fi
\makecaption{(\thesubfigure) }{#2}}
\newcommand{\dummycaption}[1][\empty]% #1 = caption text (optional)
{\ifx#1\empty\makecaption{Figure \thefigure}{}%
\else\makecaption{Figure \thefigure: }{#1}%
\fi}
\begin{document}
\listoffigures
\begin{figure}[H]
\centering%
\begin{subfigure}{.8\textwidth}
\includegraphics[width=\textwidth]{example-image-a}%
\firstsubcaption{subcaption 1}
\end{subfigure}
\begin{subfigure}{.8\textwidth}
\includegraphics[width=\textwidth]{example-image-b}%
\nextsubcaption{subcaption 2}
\end{subfigure}
\dummycaption
\end{figure}
\end{document}