
我正在嘗試使用該subcaption
包(不是 subfig
) 產生圖旁邊子圖的標籤。
我發現了很多類似的問題,但所有答案(例如這個)使用subfig
和floatrow
。我嘗試過使用floatrow
with subcaption
(請參閱下面的 MWI),但我無法產生相同的行為。我缺什麼?
手冊subcaption
明確指出
[f]或該套件的子標題功能的更高級用法
caption
,請查看該floatrow
套件
但手冊僅使用(第 75 頁)floatrow
在圖旁邊提供了標題範例。subfig
因此,非常感謝任何幫助。
微量元素:
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage[font=footnotesize,figurewithin=none]{caption}
\usepackage{subcaption}
\captionsetup{subrefformat=parens} % will result in references (typeset with \ref) like 1a but sub-references (typeset with\subref) like (a)
\usepackage{floatrow}
\floatsetup[subfigure]{style=plain,subcapbesideposition=top}
%\usepackage{subfig} % not compatible with subcaption
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.7\textwidth}
\centering
\includegraphics[width=0.7\textwidth]{example-image-a}
\caption{}
\label{subfig:a}
\end{subfigure}
\\
\begin{subfigure}[t]{0.49\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{}
\label{subfig:b}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.49\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\caption{}
\label{subfig:c}
\end{subfigure}
\caption{Caption for all subfigs: \subref{subfig:a},\subref{subfig:b}, \subref{subfig:c}}
\label{fig}
\end{figure}
\end{document}
MWE 的輸出:
答案1
與其弄清楚如何創造floatrow
工作,不如偽造它更容易。
應該注意的是,[t]
選項subfigure
指的是第一個基線,而不是絕對頂部,所以它的作用是對齊圖像的底部而不是標題。要對齊頂部,您需要使用\raisebox
.事實上,根本沒有理由將圖像放入子圖中(只是標題)。
標題的作用\raisebox
是自動在行之間產生間隙。
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage[font=footnotesize,figurewithin=none]{caption}
\usepackage{subcaption}
\captionsetup{subrefformat=parens} % will result in references (typeset with \ref) like 1a but sub-references (typeset with\subref) like (a)
%\usepackage{subfig} % not compatible with subcaption
\newcommand{\sidecaption}[1]% #1 = label name
{\raisebox{\abovecaptionskip}{\begin{subfigure}[t]{1.6em}
\caption[singlelinecheck=off]{}% do not center
\label{#1}
\end{subfigure}}\ignorespaces}
\begin{document}
\begin{figure}
\centering
\sidecaption{subfig:a}
\raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-a}}
\sidecaption{subfig:b}
\raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
\hfill
\sidecaption{subfig:c}
\raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-c}}
\caption{Caption for all subfigs: \subref{subfig:a},\subref{subfig:b}, \subref{subfig:c}}
\label{fig}
\end{figure}
\end{document}
應該注意的是,這只是格式化側邊標題的多種可能方法之一。以下根本不使用 subcaption 套件。 OTOH,它不會為\listoffigures
兩者寫入條目。
\newcounter{subfigure}[figure]% not needed with subcaption
\renewcommand{\thesubfigure}{\alph{subfigure}}
\newcommand{\sidecaption}[1]% #1 = label name
{\rule{0pt}{\abovecaptionskip}% create gap between rows
\refstepcounter{subfigure}%
\raisebox{-\height}{(\thesubfigure)~}% align
\label{#1}\ignorespaces}