Graças a esta pergunta feita anteriormenteComo conectar imagens com setas em Latex?
Consegui criar um conjunto de imagens conectadas por setas. No entanto, tenho duas perguntas:
- como rotulo cada uma das imagens (para fazer referência no texto, por exemplo, à figura 1.2 ou 1.5)
- por alguns motivos, a imagem gerada preenche toda a página (visualmente é mais de meia página) ou, pelo menos, nenhum texto é permitido na mesma página da imagem. Alguma idéia de como corrigir esse problema?
obrigado
\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}
Responder1
Se você quiser continuar com um matrix
, poderá simplificar as coisas. Primeiro, eu usaria a opção matrix of nodes
(você precisa carregar a matrix
biblioteca para isso), o que torna muito mais fácil estilizar os nós da matriz.
Então, você pode definir os rótulos automaticamente usando o figure
contador atual (e adicionando 1 a ele, porque ele só é atualizado depois de \caption
digitado) e anexar a ele o argumento fornecido por meio do seu lablum
estilo.
Observe que já é possível fazer referência a nós de matrizes usando nomes de nós específicos, por exemplo, o primeiro nó no canto superior esquerdo da sua matriz seria mat-1-1
, então você não precisa definir seus próprios nomes de nós, mas como deseja coloque as subfiguras de maneira boustrofedônica, mantive do seu jeito.
Quanto ao seu problema de a figura preencher a página inteira: provavelmente se deve ao tamanho das subfiguras. Tente escalá-los um pouco. O exemplo abaixo mostra que a figura deve ser colocada em uma página com texto, se isso for possível:
\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}
Você pode deixar TikZ/PGF também calcula os rótulos de forma totalmente automática para você (você só precisa informar de alguma forma a contagem de colunas com antecedência):
\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}
Com três colunas:
\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}
A referência é provavelmente mais fácil usando o subcaption
pacote, mas você sempre pode criar seus próprios contadores de referência (criei uma macro \refsetcounter
baseada, \refstepcounter
mas em vez de aumentar o contador, configure-o para um valor específico que é útil aqui):
\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}
Na verdade, não tenho certeza do que você está procurando. Se você quiser manter a rotulagem e as legendas personalizáveis, talvez algo assim funcione:
\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}
Adicionei alguns estilos para fazer com que as células da matriz tenham o mesmo tamanho. Para deixar isso mais claro, adicionei um pouco de cor aos nós para mostrar, que você pode simplesmente remover (excluindo fill=red!10
).
Finalmente, as coisas podem ser muito mais fáceis usando o subcaption
pacote, no entanto, você não conseguirá posicionar os nós livremente (por exemplo, da direita para a esquerda):
\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}