latexlistings

How to have separate captions in the same level in the minipage environment with listing?


In the minipage environment with listing and figure I'd like to have three separate captions a, b, c evenly as the picture below:

enter image description here

But my try with this minimal code results an untidy captions as below:

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


\begin{document}
\begin{figure}[h!]
\noindent\begin{minipage}{0.3\textwidth}
\begin{lstlisting}[]
   while(a < 0){
   a++;
}
\end{lstlisting}
\caption{C program}
\end{minipage}%
\noindent\begin{minipage}{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{Automata}
\end{minipage}%
\noindent\begin{minipage}{0.3\textwidth}
    \includegraphics[scale=0.2]{example-image-a}
    \caption{Relation}
\end{minipage}%
\caption{overal blablablablablabla  caption}
\end{figure}
\end{document}

enter image description here

How can I get rid of Figure keyword and get a, b, c caption in the same level?


Solution

  • You can [b]ottom align your minipages:

    \documentclass[11pt]{article}
    \usepackage{listings}
    \usepackage{amsmath}
    \usepackage{graphicx}
    %\usepackage{caption}
    
    
    \begin{document}
    \begin{figure}[h!]
    \noindent\begin{minipage}[b]{0.3\textwidth}
    \begin{lstlisting}[]
       while(a < 0){
       a++;
    }
    \end{lstlisting}
    \caption{C program}
    \end{minipage}%
    \noindent\begin{minipage}[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{Automata}
    \end{minipage}%
    \noindent\begin{minipage}[b]{0.3\textwidth}
        \includegraphics[scale=0.2]{example-image-a}
        \caption{Relation}
    \end{minipage}%
    \end{figure}
    \end{document}
    
        
    

    enter image description here

    The same technique works also with subfigures:

    \documentclass[11pt]{article}
    \usepackage{listings}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage{subcaption}
    
    
    \begin{document}
    \begin{figure}[h!]
    \noindent\begin{subfigure}[b]{0.3\textwidth}
    \begin{lstlisting}[]
       while(a < 0){
       a++;
    }
    \end{lstlisting}
    \caption{C program}
    \end{subfigure}%
    \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{Automata}
    \end{subfigure}%
    \noindent\begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[scale=0.2]{example-image-a}
        \caption{Relation}
    \end{subfigure}%
    \caption{text}
    \end{figure}
    \end{document}
    

    enter image description here