Mehrere zusammenhängende Bilder: Beschriftung und Seitenfüllung

Mehrere zusammenhängende Bilder: Beschriftung und Seitenfüllung

Dank dieser zuvor gestellten FrageWie verbinde ich Bilder in Latex mit Pfeilen?

Ich konnte eine Reihe von Bildern erstellen, die durch Pfeile verbunden sind. Ich habe jedoch zwei Fragen:

  • Wie beschrifte ich die einzelnen Bilder (um im Text beispielsweise auf Abbildung 1.2 oder 1.5 zu verweisen)
  • aus irgendeinem Grund füllt das generierte Bild die ganze Seite (visuell ist es eher eine halbe Seite) oder zumindest ist auf derselben Seite wie das Bild kein Text zulässig. Irgendeine Idee, wie man dieses Problem beheben kann?

Danke

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[lablum/.style={label=below:#1,name=img-#1},
marr/.style={line width=1mm,-latex}]
\matrix[column sep=1cm,row sep=5mm] (mat)
{ \node[lablum=1]{\includegraphics[width=3cm]{example-image-     duck}};
 & \node[lablum=2]{\includegraphics[width=3cm]{example-image-duck}};\\
\node[lablum=4]{\includegraphics[width=3cm]{example-image-duck}};
& \node[lablum=3]{\includegraphics[width=3cm]{example-image-duck}};\\
\node[lablum=5]{\includegraphics[width=3cm]{example-image-duck}};
& \node[lablum=6]{\includegraphics[width=3cm]{example-image-duck}};\\
};
\draw[marr] (img-1) -- (img-2);
\draw[marr] ([xshift=1mm]img-2.south east) coordinate (aux) 
-- (img-3.north-|aux);
\draw[marr] (img-3) -- (img-4);
\draw[marr] ([xshift=-1mm]img-4.south west) coordinate (aux) 
-- (img-5.north-|aux);
\draw[marr] (img-5) -- (img-6);
\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}
\end{document}

Antwort1

Wenn Sie bei einem bleiben möchten matrix, können Sie die Dinge vereinfachen. Zunächst würde ich die Option verwenden matrix of nodes(dazu müssen Sie die matrixBibliothek laden), die das Stylen der Matrixknoten erheblich vereinfacht.

Anschließend können Sie die Beschriftungen automatisch festlegen, indem Sie den aktuellen figureZähler verwenden (und 1 hinzufügen, da er erst nach dem \captionSetzen des Satzes aktualisiert wird) und ihm das Argument anhängen, das Sie über Ihren lablumStil angeben.

Beachten Sie, dass es bereits möglich ist, mit bestimmten Knotennamen auf Matrixknoten zu verweisen. Der erste Knoten in der oberen linken Ecke Ihrer Matrix wäre beispielsweise . mat-1-1Sie müssen also keine eigenen Knotennamen definieren. Da Sie die Unterabbildungen aber boustrophedonisch platzieren möchten, habe ich es bei Ihrer Vorgehensweise belassen.

Zu Deinem Problem, dass die Abbildung die ganze Seite ausfüllt: Das liegt vermutlich an der Größe der Unterabbildungen. Versuche, diese etwas zu skalieren. Das folgende Beispiel zeigt, dass die Abbildung möglichst auf einer Seite mit Text platziert werden sollte:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{figure}
\centering
\begin{tikzpicture}[
    lablum/.style={
        label=below:{\pgfmathparse{int(\thefigure+1)}\pgfmathresult.#1},
        name={img-#1},
    },
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[matrix of nodes, column sep=1cm, row sep=5mm] (mat)
{ |[lablum=1]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum=2]| \includegraphics[width=3cm]{example-image-duck} \\
  |[lablum=4]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum=3]| \includegraphics[width=3cm]{example-image-duck} \\
  |[lablum=5]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum=6]| \includegraphics[width=3cm]{example-image-duck} \\
};
\draw[marr] (img-1) -- (img-2);
\draw[marr] ([xshift=1mm]img-2.south east) coordinate (aux) 
    -- (img-3.north-|aux);
\draw[marr] (img-3) -- (img-4);
\draw[marr] ([xshift=-1mm]img-4.south west) coordinate (aux) 
    -- (img-5.north-|aux);
\draw[marr] (img-5) -- (img-6);
\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}
\end{document}

Bildbeschreibung hier eingeben


Du kannst TikZ/PGF berechnet die Beschriftungen auch komplett automatisch für Sie (Sie müssen lediglich vorher irgendwie die Spaltenanzahl angeben):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
    boustrophedon matrix/.style args={#1/#2}{
        matrix of nodes,
        nodes in empty cells, 
        boustrophedon matrix column count/.initial={#2},
        boustrophedon matrix step cell counter/.code={
            \pgfmathparse{
                mod(\pgfmatrixcurrentrow, 2) == 0 ?
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * 
                    \pgfmatrixcurrentrow -
                    \pgfmatrixcurrentcolumn + 1) :
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * 
                    (\pgfmatrixcurrentrow - 1) + 
                    \pgfmatrixcurrentcolumn)
            } 
            \global\pgfkeyslet{/tikz/boustrophedon matrix cell counter}{\pgfmathresult}
        },
        execute at begin cell={
            |[boustrophedon matrix step cell counter, label={below:{
                    \pgfmathparse{int(\thefigure+1)}\pgfmathresult.%
                    \pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}
                }
            },
            name={#1-index-\pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}}]|
        },
    },
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[boustrophedon matrix={matrix one/2}, column sep=1cm, row sep=5mm]{ 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
};

\draw[marr] (matrix one-index-1) -- (matrix one-index-2);
\draw[marr] (matrix one-index-2.south east) -- (matrix one-index-3.north east);
\draw[marr] (matrix one-index-3) -- (matrix one-index-4);
\draw[marr] (matrix one-index-4.south west) -- (matrix one-index-5.north west);
\draw[marr] (matrix one-index-5) -- (matrix one-index-6);

\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}

\end{document}

Bildbeschreibung hier eingeben

Mit drei Spalten:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
    boustrophedon matrix/.style args={#1/#2}{
        matrix of nodes,
        nodes in empty cells, 
        boustrophedon matrix column count/.initial={#2},
        boustrophedon matrix step cell counter/.code={
            \pgfmathparse{
                mod(\pgfmatrixcurrentrow, 2) == 0 ?
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * (\pgfmatrixcurrentrow) -
                    \pgfmatrixcurrentcolumn + 1) :
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * (\pgfmatrixcurrentrow - 1) + 
                    \pgfmatrixcurrentcolumn)
            } 
            \global\pgfkeyslet{/tikz/boustrophedon matrix cell counter}{\pgfmathresult}
        },
        execute at begin cell={
            |[boustrophedon matrix step cell counter, label={below:{
                    \pgfmathparse{int(\thefigure+1)}\pgfmathresult.%
                    \pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}
                }
            },
            name={#1-index-\pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}}]|
        },
    },
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[boustrophedon matrix={matrix two/3}, column sep=1cm, row sep=5mm]{ 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
};

\draw[marr] (matrix two-index-1) -- (matrix two-index-2);
\draw[marr] (matrix two-index-2) -- (matrix two-index-3);
\draw[marr] (matrix two-index-3.south east) -- (matrix two-index-4.north east);
\draw[marr] (matrix two-index-4) -- (matrix two-index-5);
\draw[marr] (matrix two-index-5) -- (matrix two-index-6);

\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}

\end{document}

Bildbeschreibung hier eingeben


Das Referenzieren ist mithilfe des subcaptionPakets wahrscheinlich einfacher, Sie können jedoch jederzeit Ihre eigenen Referenzzähler erstellen (ich habe ein Makro erstellt \refsetcounter, das auf basiert, \refstepcounterden Zähler jedoch nicht erhöht, sondern auf einen bestimmten Wert setzt, was hier praktisch ist):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\newcounter{matrix}
\newcounter{matrixnode}[matrix]
\renewcommand*{\thematrixnode}{\thematrix.\arabic{matrixnode}}

\makeatletter
\newcommand{\refsetcounter}[2]{\setcounter{#1}{#2}%
    \protected@edef\@currentlabel
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}
\makeatother

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
    boustrophedon matrix/.style args={#1/#2}{
        matrix of nodes,
        nodes in empty cells, 
        boustrophedon matrix column count/.initial={#2},
        boustrophedon matrix step cell counter/.code={
            \pgfmathparse{
                mod(\pgfmatrixcurrentrow, 2) == 0 ?
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * (\pgfmatrixcurrentrow) -
                    \pgfmatrixcurrentcolumn + 1) :
                int(\pgfkeysvalueof{/tikz/boustrophedon matrix column count} * (\pgfmatrixcurrentrow - 1) + 
                    \pgfmatrixcurrentcolumn)
            } 
            \global\pgfkeyslet{/tikz/boustrophedon matrix cell counter}{\pgfmathresult}
        },
        row 1 column 1/.append style={
            execute at begin cell={
                \refstepcounter{matrix}
            }
        },
        execute at begin cell={
            |[boustrophedon matrix step cell counter, label={below:{
                    \pgfmathparse{int(\thefigure+1)}\pgfmathresult.%
                    \pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}
                    \refsetcounter{matrixnode}{\pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}}
                    \label{matrixnode:#1-\pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}}
                }
            },
            name={#1-index-\pgfkeysvalueof{/tikz/boustrophedon matrix cell counter}}]|
        },
    },
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[boustrophedon matrix={matrix two/3}, column sep=1cm, row sep=5mm]{ 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} & 
  \includegraphics[width=3cm]{example-image-duck} \\
};

\draw[marr] (matrix two-index-1) -- (matrix two-index-2);
\draw[marr] (matrix two-index-2) -- (matrix two-index-3);
\draw[marr] (matrix two-index-3.south east) -- (matrix two-index-4.north east);
\draw[marr] (matrix two-index-4) -- (matrix two-index-5);
\draw[marr] (matrix two-index-5) -- (matrix two-index-6);

\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}

See subfigure \ref{matrixnode:matrix two-1} and \ref{matrixnode:matrix two-4}.

\end{document}

Bildbeschreibung hier eingeben

Eigentlich bin ich mir nicht ganz sicher, was Sie wollen. Wenn Sie die Beschriftung und die Untertitelung anpassbar lassen möchten, könnte vielleicht so etwas funktionieren:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\newcounter{matrix}
\newcounter{matrixnode}[matrix]
\renewcommand*{\thematrixnode}{\thematrix.\arabic{matrixnode}}

\makeatletter
\newcommand{\refsetcounter}[2]{\setcounter{#1}{#2}%
    \protected@edef\@currentlabel
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}
\makeatother

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
    my custom matrix/.style={
        matrix of nodes, 
        nodes in empty cells, 
        nodes={
            fill=red!10,
            minimum height=3.25cm,
            minimum width=3.25cm,
        },
        every label/.style={
            minimum height=0pt,
        },
        lablum/.style args={##1/##2}{
            label=below:{%
                \pgfmathparse{int(\thefigure+1)}\pgfmathresult.##1: ##2%
                \refsetcounter{matrixnode}{##1}\label{matrixnode:#1-##1}%
            },
            name={#1-index-##1},
        },
        my custom matrix initialise/.code={
            \refstepcounter{matrix}
        },
        my custom matrix initialise
    },
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[column sep=1cm, row sep=5mm, my custom matrix={mat}] { 
  |[lablum={1/my caption}]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum={2/foo}]| \includegraphics[width=3cm]{example-image-duck} \\
  |[lablum={7/bar}]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum={5/baz}]| \includegraphics[width=3cm]{example-image-duck} & 
  |[lablum={3/foo}]| \includegraphics[width=3cm]{example-image-duck} \\
};
\draw[marr] (mat-index-1) -- (mat-index-2);
\draw[marr] (mat-index-3) -- (mat-index-5);
\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}

See subfigure \ref{matrixnode:mat-1} and \ref{matrixnode:mat-5}.

\end{document}

Bildbeschreibung hier eingeben

Ich habe einige Stilelemente hinzugefügt, damit die Matrixzellen die gleiche Größe haben. Um dies deutlicher zu machen, habe ich den anzuzeigenden Knoten etwas Farbe hinzugefügt, die Sie einfach entfernen können (durch Löschen fill=red!10).


Abschließend lässt sich sagen, dass die Verwendung des Pakets möglicherweise einiges einfacher macht subcaption, allerdings ist es dann nicht mehr so ​​einfach, die Knoten frei zu positionieren (beispielsweise von rechts nach links):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{subcaption}

\captionsetup[subfigure]{labelformat=simple}
\DeclareCaptionSubType*{figure}
\renewcommand\thesubfigure{\thefigure.\arabic{subfigure}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
    marr/.style={
        line width=1mm,
        -latex
    }]
\matrix[matrix of nodes, column sep=1cm, row sep=5mm] (mat) { 
  \subcaptionbox{foo\label{subfig:1-1}}{\includegraphics[width=3cm]{example-image-duck}} & 
  \subcaptionbox{bar\label{subfig:1-2}}{\includegraphics[width=3cm]{example-image-duck}} \\
  \subcaptionbox{baz\label{subfig:1-3}}{\includegraphics[width=3cm]{example-image-duck}} & 
  \subcaptionbox{foo\label{subfig:1-4}}{\includegraphics[width=3cm]{example-image-duck}} & 
  \subcaptionbox{bar\label{subfig:1-5}}{\includegraphics[width=3cm]{example-image-duck}} \\
};
\draw[marr] (mat-1-1) -- (mat-1-2);
\end{tikzpicture}
\caption{A matrix of figures.}
\label{fig:pffft}
\end{figure}

See subfigure \ref{subfig:1-1} and \ref{subfig:1-5}.

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen