我想在一个有两列的图形中放置 3 个子图。右边有一个大子图。左边的两个子图应该对齐,以便第一个与大子图的顶部对齐,第二个与大子图的标题对齐。
\begin{figure}[h!]
\begin{minipage}[t]{0.49\linewidth}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
.. Before
.. Original code
}
\end{lstlisting}
\caption{Before-Advice}
\label{fig:before}
\end{subfigure}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
.. Around ( *(Original code) )
}
\end{lstlisting}
\caption{Around-Advice}
\label{fig:around}
\end{subfigure}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{subfigure}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
try {
.. Original code
.. After returning
}
catch (...) {
.. After throwing
}
finally {
.. After
}
}
\end{lstlisting}
\caption{After-Advices}
\label{fig:after}
\end{subfigure}
\end{minipage}
\caption{Advice-Arten}
\label{fig:advices}
\end{figure}
答案1
这是一个可能的解决方案。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{subcaption}
\usepackage{listings}
\begin{document}
\newsavebox{\temp}
\begin{lrbox}{\temp}
\begin{minipage}{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
try {
.. Original code
.. After returning
}
catch (...) {
.. After throwing
}
finally {
.. After
}
}
\end{lstlisting}
\end{minipage}
\end{lrbox}
\newlength{\tempd}
\newlength{\tempc}
\settoheight{\tempd}{\usebox{\temp}}
\settodepth{\tempc}{\usebox{\temp}}
\addtolength{\tempd}{\tempc}
\begin{figure}[h!]
\begin{minipage}[c]{0.49\linewidth}
\begin{minipage}[t][\tempd][c]{\linewidth}
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
.. Before
.. Original code
}
\end{lstlisting}
\subcaption{Before-Advice}
\label{fig:before}
\vfill
\begin{lstlisting}[language=c,escapechar=+]
+{public void}+ Method () {
.. Around ( *(Original code) )
}
\end{lstlisting}
\end{minipage}
\subcaption{Around-Advice}
\label{fig:around}
\end{minipage}
\begin{minipage}[c][\tempd][c]{0.49\linewidth}%
\usebox{\temp}
\subcaption{After-Advices}
\label{fig:after}
\end{minipage}
\caption{Advice-Arten}
\label{fig:advices}
\end{figure}
This is a reference to subfigure \ref{fig:after}
\end{document}
这个想法是计算较长列表的总高度,然后将minipage
包裹左侧两个列表和右侧列表的 s 的高度设置为该测量值。问题是我们不能\caption
在浮点数之外使用,因此我们必须使用额外的minipage
作为包装器并封闭标题。该包subcaption
用于生成子图的标题。