如何垂直对齐两个具有子图和不同标题长度的小页面?

如何垂直对齐两个具有子图和不同标题长度的小页面?

下列的 ”将两个图形(每个都有子图形)并排放置",我使用了下面的代码来将两个带有子图的图形并排放置,并将子图垂直放置:

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.

\begin{document}

\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig1}}\\
\subfloat[]{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures with very very very very long caption}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig3}}\\
\subfloat[]{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}

\end{document} 

这已经是我想要的样式了,但如果标题不同,看起来就不太好看,因为这会导致相邻的图片的高度不一样。我该如何改变这种情况?我尝试在每张图片周围放置一个小页面,但这并没有改变任何东西。


编辑

实际上,我觉得我并没有真正问对问题,抱歉!事实上,每个图都有三个子图minipage,每个子图都有一个标题,这些标题的长度不同。在这种情况下,将两个图对齐在顶部或底部对我没有帮助,因为子图仍然不匹配。很抱歉一开始没有更好地解释这一点。

答案1

您可以使用st作为可选参数,以minipage在顶部进行垂直对齐:

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.

\begin{document}

\begin{figure}
\begin{minipage}[t]{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig1}}\\
\subfloat[]{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures with very very very very long caption}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}[t]{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig3}}\\
\subfloat[]{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}

\end{document} 

在此处输入图片描述

对问题进行编辑后:同样的想法(minipage如果 sucaptions 具有不同的高度,则可以使用具有适当垂直对齐方式的 s );现在,的第二个可选参数minipage可用于指定其高度;这将保证左侧的每个图像都与右侧对应的图像放置在相同的高度:

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.

\begin{document}

\begin{figure}
\begin{minipage}[t]{.48\textwidth}
\centering
\begin{minipage}[t][5cm][t]{\linewidth}
  \centering
  \subfloat[a little longer text here; it will span several lines]{\includegraphics[width=.4\linewidth]{fig1}}
\end{minipage} \\
\begin{minipage}[t][6cm][t]{\linewidth}
  \centering
  \subfloat[a little longer text here; it will span several lines just for illustration in this example]{\includegraphics[width=.4\linewidth]{fig2}}
\end{minipage} \\
\begin{minipage}[t][5cm][t]{\linewidth}
  \centering
  \subfloat[a little longer text here; it will span several lines]{\includegraphics[width=.4\linewidth]{fig3}}
\end{minipage}
\caption{First figure with two subfigures with very very very very long caption}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}[t]{.48\textwidth}
\centering
\begin{minipage}[t][5cm][t]{\linewidth}
  \centering
  \subfloat[short text]{\includegraphics[width=.4\linewidth]{fig4}}
\end{minipage} \\
\begin{minipage}[t][6cm][t]{\linewidth}
  \centering
  \subfloat[short text]{\includegraphics[width=.4\linewidth]{fig5}}
\end{minipage} \\
\begin{minipage}[t][5cm][t]{\linewidth}
  \centering
  \subfloat[short text]{\includegraphics[width=.4\linewidth]{fig6}}
\end{minipage}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}

\end{document} 

在此处输入图片描述

甚至可以自动计算所需的高度。

现在,评论中提到,图像可能有不同的高度(和宽度,所以这并不重要);在这种情况下,可以使用包中的tabular和;必须对计数器做一些仔细的工作:\captionofsubcaption

\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage{array}
\usepackage{subcaption}

\captionsetup[subfigure]{size=footnotesize,labelformat=parens,labelsep=space}

\newcolumntype{C}{>{\centering\arraybackslash}p{0.4\linewidth}}
\newcounter{oldfig}

\begin{document}

\begin{figure}[!ht]
\begin{tabular}{CC}
\stepcounter{figure}
\setcounter{oldfig}{\value{figure}}
\stepcounter{oldfig}
\includegraphics[width=.6\linewidth,height=1cm]{fig1}
& 
\includegraphics[width=.3\linewidth,height=2cm]{fig4} 
\\
\captionof{subfigure}{a little longer text here; it will span several lines}\label{sfig:11}
& 
\setcounter{figure}{\value{oldfig}}
\addtocounter{subfigure}{-1}
\captionof{subfigure}{short text}\label{sfig:12} 
\\
\includegraphics[width=.4\linewidth,height=1cm]{fig2}
& 
\includegraphics[width=.5\linewidth,height=2cm]{fig5} 
\\
\addtocounter{figure}{-1}
\captionof{subfigure}{a little longer text here; it will span several lines just for illustration in this example}\label{sfig:21} 
&
\stepcounter{figure} 
\stepcounter{subfigure} 
\addtocounter{subfigure}{0}
\setcounter{figure}{\value{oldfig}}
\captionof{subfigure}{short text}\label{sfig:22} 
\\
\includegraphics[width=.4\linewidth]{fig3}
&
\includegraphics[width=.2\linewidth,height=2.4cm]{fig6} 
\\
\addtocounter{figure}{-1}
\captionof{subfigure}{a little longer text here; it will span several lines}\label{sfig:31} 
& 
\stepcounter{figure} 
\stepcounter{subfigure} 
\addtocounter{subfigure}{1}
\setcounter{figure}{\value{oldfig}}
\captionof{subfigure}{short text}\label{sfig:32} 
\\
\addtocounter{figure}{-2}
\captionof{figure}{First figure with two subfigures with very very very very long caption}\label{fig:testa}
& 
\captionof{figure}{second figure with short caption}\label{fig:testb} 
\end{tabular}
\end{figure}

Some references to figures ~\ref{fig:testa} and \ref{fig:testb}.

Some references to subfigures ~\ref{sfig:11}, \ref{sfig:12}, \ref{sfig:21}, \ref{sfig:22}, \ref{sfig:31}, and~\ref{sfig:32}.


\end{document}

在此处输入图片描述

相关内容