我试图将子图的子标题放在每幅图像的左侧。为了说明这一点,我附上了所需结果的图像和相应的 MWE。
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=2.5cm,bottom=3cm,left=3cm,right=3cm]{geometry}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.55\textwidth}
\includegraphics[width=1\linewidth]{example-image-a}
\caption{}
\label{fig:Ng1}
\end{subfigure}
\begin{subfigure}[b]{0.55\textwidth}
\includegraphics[width=1\linewidth]{example-image-b}
\caption{}
\label{fig:Ng2}
\end{subfigure}
\caption{Here is my main caption. (a) is a subcaption. (b) is a subcaption.}
\end{figure}
\end{document}
答案1
这里我定义了一个varsubfigure
环境,其中数字根据环境内容居中排版。请注意,标签位于零宽度框中。
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=2.5cm,bottom=3cm,left=3cm,right=3cm]{geometry}
\usepackage{subcaption}
\usepackage{graphicx}
%\usepackage{xparse} % uncomment if using LaTeX released prior to 2020-10-01
\NewDocumentEnvironment{varsubfigure}{O{c}mo}
{% #1 = optional positioning argument, #2 = width, #3 = label
\begin{subfigure}[#1]{#2}
\if#1t\vspace{0pt}\fi
\makebox[0pt][r]{%
\refstepcounter{subfigure}%
\IfValueT{#3}{\label{#3}}%
(\thesubfigure) % <--- a space here
}%
\begin{tabular}{@{}p{\textwidth}@{}}
}
{\end{tabular}\if#1b\vspace{0pt}\fi\end{subfigure}}
\begin{document}
\begin{figure}
\centering
\begin{varsubfigure}{0.55\textwidth}[fig:Ng1]
\includegraphics[width=1\linewidth]{example-image-a}
\end{varsubfigure}
\begin{varsubfigure}{0.55\textwidth}[fig:Ng2]
\includegraphics[width=1\linewidth]{example-image-b}
\end{varsubfigure}
\caption{Here is my main caption. (a) is a subcaption. (b) is a subcaption.}
\end{figure}
\begin{figure}
\centering
\begin{varsubfigure}[b]{0.33\textwidth}[fig:Ng1-2]
\includegraphics[width=1\linewidth]{example-image-a}
\end{varsubfigure}\hfil
\begin{varsubfigure}[b]{0.20\textwidth}[fig:Ng2-2]
\includegraphics[width=1\linewidth]{example-image-b}
\end{varsubfigure}
\caption{Here is my main caption. (a) is a subcaption. (b) is a subcaption.}
\end{figure}
\end{document}
答案2
试试这个代码:
\documentclass{memoir}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\parbox[b]{0.30\textwidth}{\subcaption{First sub with more text. More text. First sub with more text.}} \quad \parbox[b]{0.65\textwidth}{\includegraphics[width=\hsize]{example-image}}
\\[.5cm]
\parbox[b]{0.30\textwidth}{\subcaption{Second sub}} \quad\parbox[b]{0.65\textwidth}{\includegraphics[width=\hsize]{example-image}}
\\[.5cm]
\parbox[b]{0.30\textwidth}{\subcaption{Third sub}} \quad \parbox[b]{0.65\textwidth}{\includegraphics[width=\hsize]{example-image}}
\caption{The main figure}
\end{figure}
\end{document}
您将获得以下结果:
答案3
只是为了好玩。请注意,您无法使图像\linewidth
变宽并为子标题留出空间。您也不知道子标题通常有多大。
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=2.5cm,bottom=3cm,left=3cm,right=3cm]{geometry}
\usepackage{subcaption}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\newcommand{\sidecaption}[2][\empty]% #1=caption, #2=image
{\bgroup% use local registers
\sbox0{#2}% measure image
\rotatebox[origin=Bl]{90}{\parbox{\ht0}{\subcaption[position=above]{#1}}}%
\usebox0
\egroup}
\begin{document}
\begin{figure}
\centering
\sidecaption[Some text here\label{fig:Ng1}]{\includegraphics[width=0.7\textwidth]{example-image-a}}
\sidecaption[\label{fig:Ng2}]{\includegraphics[width=0.7\textwidth]{example-image-b}}
\caption{Here is my main caption. (a) is a subcaption. (b) is a subcaption.}
\end{figure}
\ref{fig:Ng1} and \ref{fig:Ng2}.
\end{document}