尽管使用了 `[b]` 参数,但小页面/子图中的第一行标题不在同一高度

尽管使用了 `[b]` 参数,但小页面/子图中的第一行标题不在同一高度

我修改了代码这个问题如下:

\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[h!]
\noindent\begin{subfigure}[b]{0.45\textwidth}
    \begin{align*}
    &F_1(a, b) \leftarrow a \le 0 \\ 
    &F_2(a, b) \leftarrow  F_1(a, b) \\ 
    \end{align*}
\caption{bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla}
\end{subfigure}%
\noindent\begin{subfigure}[b]{0.45\textwidth}
\begin{lstlisting}[]
   while(a < 0){
   a++;
}
\end{lstlisting}
\caption{bla bla bla bla, blsdf asdf asdf asdfasdfasdf asdfa bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, blablabasdf asdf asdf asdf }
\end{subfigure}%
\caption{text}
\end{figure}
\end{document}

虽然我使用了参数[b],但两个子图的标题第一行的高度并不相同,并且相互重叠。我做错了什么?

在此处输入图片描述

编辑 感谢 leandriis 的评论,我可以解决重叠问题

\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[h!]
\begin{subfigure}[b]{0.45\textwidth}
    \begin{align*}
    &F_1(a, b) \leftarrow a \le 0 \\ 
    &F_2(a, b) \leftarrow  F_1(a, b) \\ 
    \end{align*}
\caption{bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla}
\end{subfigure}%
\hfill
\begin{subfigure}[b]{0.45\textwidth}
\begin{lstlisting}[]
   while(a < 0){
   a++;
}
\end{lstlisting}
\caption{bla bla bla bla, blsdf asdf asdf asdfasdfasdf asdfa bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, blablabasdf asdf asdf asdf }
\end{subfigure}%
\caption{text}
\end{figure}
\end{document}

在此处输入图片描述

答案1

将列表内容存储在一个盒子里第一的然后使用该框作为以下部分subfigure

在此处输入图片描述

\documentclass{article}

\usepackage{listings}
\usepackage{amsmath}
\usepackage{subcaption}

\newsavebox{\codebox}

\begin{document}

\begin{figure}
  \begin{subfigure}[b]{0.45\linewidth}
    \begin{align*}
      &F_1(a, b) \leftarrow a \leq 0   \\ 
      &F_2(a, b) \leftarrow  F_1(a, b)
    \end{align*}
    \caption{bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.45\linewidth}
    \begin{lstlisting}[basicstyle=\ttfamily]
while(a < 0) {
 a++;
}
    \end{lstlisting}
    \caption{bla bla bla bla, blsdf asdf asdf asdfasdfasdf asdfa bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, blablabasdf asdf asdf asdf}
  \end{subfigure}
  \caption{Without storing \texttt{lstlisting} in a box \emph{first}.}

  \bigskip
  
  \subcaptionbox{bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla}[0.45\linewidth][b]{%
    \begin{align*}
      &F_1(a, b) \leftarrow a \leq 0   \\ 
      &F_2(a, b) \leftarrow  F_1(a, b)
    \end{align*}
  }%
  \hfill
  % Store listing inside \codebox
  \begin{lrbox}{\codebox}
    \begin{lstlisting}[basicstyle=\ttfamily]
while(a < 0){
 a++;
}
    \end{lstlisting}
\end{lrbox}%
  \subcaptionbox{bla bla bla bla, blsdf asdf asdf asdfasdfasdf asdfa bla bla bla, bla bla bla bla, bla bla bla bla, bla bla bla bla, blablabasdf asdf asdf asdf}[0.45\linewidth][b]{%
    \usebox{\codebox}%
  }%
  \caption{Storing \texttt{lstlisting} in a box \emph{first}.}
\end{figure}

\end{document}

相关内容