四个数字下有两个标题,包含在小页中

四个数字下有两个标题,包含在小页中

我有四幅图,我想在每组两幅图的下方居中放置两个标题,而不是在所有四幅图下方放置一个标题(见下图)。但是,如果我尝试在前两页小页后插入标题,所有图的对齐都会变得混乱。如何正确完成此操作?在此处输入图片描述

\begin{figure}
    \centering
    % + +
    \begin{minipage}{.2\textwidth}
        \begin{tikzpicture}[transform canvas={scale=0.5}]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {0};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,0);
        \end{axis}
        \end{tikzpicture}
    \end{minipage}\hfill
    \begin{minipage}{.2\textwidth}
        \begin{tikzpicture}[transform canvas={scale=0.5}]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {x};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,1);
        \end{axis}
        \end{tikzpicture}
    \end{minipage}\hfill\quad\quad
    % + -
    \begin{minipage}{.2\textwidth}
        \begin{tikzpicture}[transform canvas={scale=0.5}]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {0};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        };
        \addplot [only marks, mark = -, color = blue] table {
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,0);
        \end{axis}
        \end{tikzpicture}
    \end{minipage}\hfill
    \begin{minipage}{.2\textwidth}
        \begin{tikzpicture}[transform canvas={scale=0.5}]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {-x};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        };
        \addplot [only marks, mark = -, color = blue] table {
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,-1);
        \end{axis}
        \end{tikzpicture}
    \end{minipage}
    \caption{Caption}
    \label{fig:my_label}

答案1

我假设你喜欢这样的东西:

在此处输入图片描述

为了获得这张照片我做了以下事情:

  • 仅使用两个小页面,每个小页面用于一个表格环境
  • 在表格环境中放置您的图像
  • 稍微改变你的形象 - 使它们变小并省略画布变换(这可能很棘手)
  • 在每个小页面上添加一个标题

完整代码如下:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\usepackage[margin=30mm]{geometry}

\begin{document}
\begin{figure}[h]
\begin{minipage}{.48\textwidth}
    \begin{tabular}{cc}
        \begin{tikzpicture}[scale=0.45]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {0};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,0);
        \end{axis}
        \end{tikzpicture}

&         \begin{tikzpicture}[scale=0.45]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {x};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,1);
        \end{axis}
        \end{tikzpicture}

    \end{tabular}
\caption{Caption A}
\label{fig:my_label-A}
    \end{minipage}
\hfill
    \begin{minipage}{.48\textwidth}\centering
    \begin{tabular}{cc}
        \begin{tikzpicture}[scale=0.45]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {0};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        };
        \addplot [only marks, mark = -, color = blue] table {
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,0);
        \end{axis}
        \end{tikzpicture}
&
        \begin{tikzpicture}[scale=0.45]
        \begin{axis}[
                axis lines=middle,
                grid = major,
                xmin=-2, xmax=2,
                ymin=-2, ymax=2,
                xlabel=$x_1$,
                ylabel=$x_2$,
                xtick={-2,-1,0,...,2},
                ytick={-2,-1,0,...,2}]
        \addplot [thin, samples=100] {-x};
        \addplot [only marks, mark = +, color = red] table {
        -1 0
        };
        \addplot [only marks, mark = -, color = blue] table {
        0 1
        };
        \draw [-latex, red, thick] (0,0) -- (-1,-1);
        \end{axis}
        \end{tikzpicture}
    \end{tabular}
    \caption{Caption B}
    \label{fig:my_label}
    \end{minipage}
\end{figure}
\end{document}    

相关内容