如何让子图形更加接近?

如何让子图形更加接近?
\begin{figure}[t]
    \centering
    \begin{tikzpicture}[row sep=-0.3in]
    \matrix (fig)[matrix of nodes]{
        \includegraphics[width=3in]{1.pdf}  \\
        \includegraphics[width=3in]{2.pdf}    \\
        \includegraphics[width=3in]{3.pdf}    \\};
    \end{tikzpicture}
    \caption{}
\end{figure}

我绘制了三个子图,并希望它们之间的距离更近。一旦我设置了row sep一个较小的数字,子图就会相互重叠,尽管它们之间仍然有一些空间。

问题:

  1. 如何使它们更接近而不覆盖 x 和 y 轴的刻度?

  2. 如何为整个图形添加 x 和 y 标签?

答案1

对于 1),我想你必须裁剪图片。对于 2),我使用boundingbox

为了了解如何裁剪,我将第一张图片包裹在 中tikzpicture并添加了一个网格。请确保为 赋予正确的值row sep:使用负值,在我的测试中,图片显然重叠。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{graphicx}

\begin{document}
    \begin{figure}[t]
        \centering
        \begin{tikzpicture}[row sep=-0.3in]
        \matrix (fig)[matrix of nodes]{
            \begin{tikzpicture}
                \node {\includegraphics[width=3in]{example-image-a}};
                \draw[step=.1,gray, very thin] (current bounding box.south west) grid (current bounding box.north east);
                \draw[step=.5,blue, very thin] (current bounding box.south west) grid (current bounding box.north east);
                \draw[step=1.0, red, thin] (current bounding box.south west) grid (current bounding box.north east);
            \end{tikzpicture}  \\
            \includegraphics[width=3in,clip,trim={5cm 0 0 0}]{example-image-b}\\ % <- just to show trim and clip
            \includegraphics[width=3in]{example-image-c}\\};
        \path (current bounding box.south west) -- (current bounding box.south east) node [pos=.5, below] {x label};
        \path (current bounding box.south west) -- (current bounding box.north west) node [pos=.5, left, sloped] {y label};
        \end{tikzpicture}
        \caption{}
    \end{figure}
\end{document}

在此处输入图片描述

编辑

在每个矩阵节点上添加标签。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{graphicx}

\begin{document}
    \begin{figure}[t]
        \centering
        \begin{tikzpicture}[row sep=-0.3in]
        \matrix (fig)[matrix of nodes]{
            \begin{tikzpicture}
                \node {\includegraphics[width=3in]{example-image-a}};
                \draw[step=.1,gray, very thin] (current bounding box.south west) grid (current bounding box.north east);
                \draw[step=.5,blue, very thin] (current bounding box.south west) grid (current bounding box.north east);
                \draw[step=1.0, red, thin] (current bounding box.south west) grid (current bounding box.north east);
            \end{tikzpicture}  \\
            \includegraphics[width=3in,clip,trim={5cm 0 0 0}]{example-image-b}\\ % <- just to show trim and clip
            \includegraphics[width=3in]{example-image-c}\\};
        \path (current bounding box.south west) -- (current bounding box.south east) node [pos=.5, below] {x label};
        \path (current bounding box.south west) -- (current bounding box.north west) node [pos=.5, above=5pt, sloped] {y label};
        \node at (fig-1-1.west) [rotate=90, above=3pt] {label A};
        \node at (fig-2-1.west) [rotate=90, above=3pt] {label B};
        \node at (fig-3-1.west) [rotate=90, above=3pt] {label C};
        \end{tikzpicture}
        \caption{}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容