使用 TikZ 矩阵进行数组对齐;单元格覆盖整行

使用 TikZ 矩阵进行数组对齐;单元格覆盖整行

我想在 pgfplot 中对齐子图。

使用\matrix它很容易对齐图片。我的问题是,我需要几行两列/图片,最后一行两列上都有一张图片。

下面是不起作用的代码,说明了我想做的事情

\documentclass[a4paper,oneside,10pt]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[USenglish]{babel}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{figure} [H]
    \centering
    \begin{tikzpicture}
        \matrix{
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        &
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        \\
        \begin{axis}[width=0.9\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        \\  
        };
\end{tikzpicture}
\end{figure}


\end{document}

这就是不想要的结果

在此处输入图片描述

这就是我想要的效果

在此处输入图片描述

我看了

  • 由 Christian Feuersaenger 编写的 pgfplots 软件包手册
  • TikZ 和 PGF 手册(作者:Till Tantau)

但没有找到解决方案(也许没有)

是否有人有使用 /matrix 实现此目的的解决方案(非常感谢)或者可能有其他解决方案?

问候本杰明

答案1

可能\hspaces需要进行调整,但对齐问题因水平轴标签(在某些情况下但不是所有情况下)超出图形的边界框而变得更加复杂,并且因为并非所有垂直轴标签的宽度都相同(因为有负数)。\stackon默认情况下,底层方法是居中对齐。如果您认为将其左对齐可能会使事情变得更容易,\def\stackalignment{l}那么在开始之前就可以实现它。

\documentclass[a4paper,oneside,10pt]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[USenglish]{babel}
\usepackage{stackengine}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{figure} [H]
    \centering
\stackon[5pt]{%
    \begin{tikzpicture}
        \begin{axis}[width=0.9\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}
}{%
    \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}%
\hspace{5.5ex}%
    \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}
\hspace{1ex}%
}
\end{figure}


\end{document}

在此处输入图片描述

相关内容