2 列文档中的 2 x 2 子图数组

2 列文档中的 2 x 2 子图数组

我有一个包含 4 个子图的图形。我想要将它们排列为 2x2 数组,放在 2 列文档的单列中,而不是整个 A4 页面中。

这是我的代码:

\begin{figure}[h]
\centering
\begin{subfigure}[t]{0.25\textwidth}
    \centering
    \includegraphics[width=\textwidth]{PWM_with_DK}
    \caption{PWM of Motor 1 with no anti-derivative kick logic implemented}
    \label{PWM_with_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
  %(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.25\textwidth}
    \centering
    \includegraphics[width=\textwidth]{GameRV_with_DK}
    \caption{The set point Yaw angle with no anti-derivative kick logic implemented}
    \label{GameRV_with_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.25\textwidth}
    \centering
    \includegraphics[width=\textwidth]{PWM_anti_DK}
    \caption{PWM of Motor 1 with anti-derivative kick logic implemented}
    \label{PWM_anti_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.25\textwidth}
    \centering
    \includegraphics[width=\textwidth]{GameRV_anti_DK}
    \caption{The set point Yaw angle with anti-derivative kick logic implemented}
    \label{PWM_anti_DK}
\end{subfigure}
\caption{Anti-Derivative Kick effect}\label{fig:animals}
\end{figure}

但我得到的结果如图所示。

在此处输入图片描述

任何帮助都将受到高度赞赏。

答案1

注意:几乎任何以 结尾的行}都会在末尾添加一个空格(~也会添加空格)。这可以使行在此点中断,但也会使行宽略微增加。换句话说,\columnwidth对于一行来说,加上 1 个空格就太大了。

\documentclass[twocolumn]{article}
\usepackage{subcaption}
\usepackage{mwe}

\newlength{\tempdima}

\begin{document}
\lipsum[1]

\begin{figure}[h]
\centering
\begin{subfigure}[t]{0.45\columnwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-a}
    \caption{PWM of Motor 1 with no anti-derivative kick logic implemented}
    \label{PWM_with_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
  %(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.45\columnwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{The set point Yaw angle with no anti-derivative kick logic implemented}
    \label{GameRV_with_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.45\columnwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-c}
    \caption{PWM of Motor 1 with anti-derivative kick logic implemented}
    \label{PWM_anti_DK}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc. 
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[t]{0.45\columnwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{The set point Yaw angle with anti-derivative kick logic implemented}
    \label{PWM_anti_DK}
\end{subfigure}
\caption{Anti-Derivative Kick effect}\label{fig:animals}
\end{figure}

\lipsum[2]
\end{document}

相关内容