上面的图片是我可以用以下方式生成的:
\begin{figure*}
\begin{subfigure}[b]{0.3\textwidth}
\begin{lstlisting}[language=Java]
...java code...
\end{lstlisting}
\caption{Java source code that loads files from HDFS}
\label{fig:javaloadhdfs}
\end{subfigure}\hfill
~
\begin{subfigure}[b]{0.3\textwidth}
\begin{lstlisting}[language=C]
...c code...
\end{lstlisting}
\caption{C source code that loads files from HDFS}
\label{fig:cloadhdfs}
\end{subfigure}
~
\begin{subfigure}[b]{0.3\textwidth}
\begin{lstlisting}[language=bash]
...bash code...
\end{lstlisting}
\caption{Bash source code that loads files from HDFS}
\label{fig:bashloadhdfs}
\end{subfigure}
\caption{Example programs that load files from HDFS and count the number of non-whitespace characters}
\end{figure*}
我如何将 (b) 移动到 (c) 上方,使得 (a) 位于左列,而 (b)、(c) 堆叠在右列?
我一直试图将其制作成一张表格,然后使用multirow
或subfloat
使(a)跨越两行,但到目前为止还没有成功。
我应该如何解决这个问题?
答案1
您可以将右侧的两个子图嵌套在它们自己的子图中以获得所需的布局。
\documentclass{article}
\usepackage{listings}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{.5\linewidth}%left
\begin{lstlisting}[language=Java]
First line
Second line
Third line
Fourth line
Fifth line
Sixth line
\end{lstlisting}
\caption{subcaption}
\end{subfigure}
\begin{subfigure}{.5\linewidth}%right
\begin{subfigure}{\linewidth}%right upper
\begin{lstlisting}[language=Java]
First line
Second line
\end{lstlisting}
\caption{subcaption}
\end{subfigure}
\begin{subfigure}{\linewidth}%right lower
\begin{lstlisting}[language=Java]
First line
Second line
Third line
\end{lstlisting}
\caption{subcaption}
\end{subfigure}
\end{subfigure}
\caption{caption}
\end{figure}
\end{document}