副标题:图像水平对齐

副标题:图像水平对齐

我目前想描述一个算法是如何工作的。该算法使用三个不同的步骤,这些步骤被重复调用。

所以我想要这样的结果:

预测结果

但目前我只能得到

当前的

我的消息来源:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    \centering
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
\end{figure}

\end{document}

我已经有了添加两个虚拟图像来存档我想要的结果的想法

\subcaptionbox{}{
    \phantomcaption
    \begin{tikzpicture}
    \draw[opacity=0] (0, 0) rectangle (4, 2.5);
    \end{tikzpicture}
}

但使用 phantomcaption 只会导致标题改变(总是“a”而不是“e”和“f”,而我期望删除标题)

答案1

您可以使用两张\phantom图片:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    \centering
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }\par
    \subcaptionbox{}{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}%
    }
        \phantom{\begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}}
        \phantom{\begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}}%
\end{figure}

\end{document}

在此处输入图片描述

答案2

使用表格:

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
\centering
\begin{tabular}{@{}l@{ }l@{ }l@{}}
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
&
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
&
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
\\
\subcaptionbox{}{%
  \begin{tikzpicture}
  \draw (0, 0) rectangle (4, 2.5);
  \end{tikzpicture}%
}
\end{tabular}
\end{figure}

\end{document}

%请注意,在某些行末尾给出了针对虚假空格的保护。

在此处输入图片描述

答案3

简单的解决方案

如果希望子图占据整个文本宽度,请不要使用\centering并放在\hfill每个子图之间

\documentclass{scrbook}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}

\begin{document}

Test
\begin{figure}[h]
    %\centering
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \hfill
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
    \hfill
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    } \\
    \subcaptionbox{}{
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
    }
\end{figure}

\end{document}

维苏

答案4

使用以下软件包的解决方案floatrow

\documentclass{scrbook}

\usepackage{pgfplots}
%\pgfplotsset{compat=1.12}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage{floatrow}
\DeclareFloatVCode{myrowsep}{\vskip 2.5ex}

%\usepackage[showframe]{geometry}

\begin{document}
\setcounter{chapter}{1}
Test
\begin{figure}[h]
\floatsetup{justification =centering, rowpostcode=myrowsep}
\ffigbox{
\begin{subfloatrow}[3]
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-a}}
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-b}}
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-c}}
\end{subfloatrow}
\begin{subfloatrow}[3]
\ffigbox{%
        \begin{tikzpicture}
        \draw (0, 0) rectangle (4, 2.5);
        \end{tikzpicture}
}{\caption{}\label{fig-d}}
\hspace*{0.667\linewidth}
\end{subfloatrow}
}
{\caption{Four images}\label{4im}}
\end{figure}

\end{document} 

在此处输入图片描述

相关内容