回忆垂直对齐子图的方法

回忆垂直对齐子图的方法

当有两个不同大小的子图时,有没有办法垂直对齐它们?

梅威瑟:

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{duckuments}
\usepackage{graphicx}
\newsubfloat{figure}
\begin{document}

\begin{figure}
    \centerfloat
    \subbottom[]{\includegraphics[height = 2cm]{example-image-duck}}~%
    \subbottom[]{\includegraphics{example-image-duck}}
    \caption{The two figures should be vertically aligned}
\end{figure}

\end{document}

生成:

G 我希望两个图形中的水平线对齐。有没有什么很酷的方法来做到这一点?

答案1

答案已更新:

输出 输出

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
%----------------------------------------------------------------
\begin{figure}
    \begin{subfigure}[t]{0.5\textwidth}% Takes half the text width (left to center)
        \includegraphics[width=\textwidth, height = 2cm]{example-image-a}
        \caption{A long caption of the subcaption of the left subfigure}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{0.5\textwidth}% Takes half the text width, (other half center to right)
        \includegraphics[width=\textwidth]{example-image-b}
        \caption{
            A long caption of the subcaption of the right subfigure copied and 
            pasted twice a long caption of the subcaption of the right subfigure
        }
    \end{subfigure}
    \caption{Overall Overall Overall Overall Overall Overall Overall Overall caption}
\end{figure}

%----------------------------------------------------------------
\begin{figure}
    \begin{subfigure}[t]{0.4\textwidth}% Takes half the text width (left to center)
        \includegraphics[width=\textwidth, height = 2cm]{example-image-a}
        \caption{A long caption of the subcaption of the left subfigure}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{0.4\textwidth}% Takes half the text width, (other half center to right)
        \includegraphics[width=\textwidth]{example-image-b}
        \caption{
            A long caption of the subcaption of the right subfigure copied and 
            pasted twice a long caption of the subcaption of the right subfigure
        }
    \end{subfigure}
    \caption{Overall Overall Overall Overall Overall Overall Overall Overall caption}
\end{figure}

%----------------------------------------------------------------
\begin{figure}
    \begin{subfigure}[t]{0.7\textwidth}% Takes half the text width (left to center)
        \includegraphics[width=\textwidth, height = 2cm]{example-image-a}
        \caption{A long caption of the subcaption of the left subfigure}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{0.2\textwidth}% Takes half the text width, (other half center to right)
        \includegraphics[width=\textwidth]{example-image-b}
        \caption{A long caption of the subcaption of the right subfigure}
    \end{subfigure}
    \caption{Overall Overall Overall Overall Overall Overall Overall Overall caption}
\end{figure}
\end{document}

上一个答案:

您可以使用graphbox允许您指定所需对齐类型的包。您可以将其align = t用于顶部对齐、align = c居中或align = b底部对齐。

旧输出

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{graphbox}   % Need this!
\newsubfloat{figure}
\begin{document}

\begin{figure}
    \centerfloat
    \subbottom[]{\includegraphics[height = 1cm, align = t]{example-image-a}}
    \subbottom[]{\includegraphics[height = 2cm, align = t]{example-image-b}}
    \caption{The two figures should be vertically aligned (top)}
\end{figure}
\vspace*{-3cm}
\begin{figure}
    \centerfloat
    \subbottom[]{\includegraphics[height = 1cm, align = c]{example-image-a}}
    \subbottom[]{\includegraphics[height = 2cm, align = c]{example-image-b}}
    \caption{The two figures should be vertically aligned (center)}
\end{figure}
\vspace*{-3cm}
\begin{figure}
    \centerfloat
    \subbottom[]{\includegraphics[height = 1cm, align = b]{example-image-a}}
    \subbottom[]{\includegraphics[height = 2cm, align = b]{example-image-b}}
    \caption{The two figures should be vertically aligned (bottom)}
\end{figure}
\end{document}

相关内容