1

I need to arrange several pictures, then labelling each picture and draw arrows between some labels (of the same and also different pictures). I think this can be done with tikzpictures in tabular. So far I have this MWE:

\documentclass{article}

\usepackage{tikz, tabularray}

\begin{document}

\begin{tblr}{colspec={X[c]X[c]}, rows={m}, cell{2}{1}={r=2}{}} \tikz[overlay, remember picture] \node[inner sep=0pt] (im1) at (0,0) {\includegraphics[width=0.4\textwidth]{example-image-a}}; & \tikz[overlay, remember picture] \node[inner sep=0pt] (im2) at (0,0)
{\includegraphics[width=0.4\textwidth]{example-image-b}}; \[1cm] \tikz[overlay, remember picture] \node[inner sep=0pt] (im3) at (0,0) {\includegraphics[width=0.4\textwidth]{example-image-c}}; & \tikz[overlay, remember picture] \node[inner sep=0pt] (im4) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image}}; \ & \tikz[overlay, remember picture] \node[inner sep=0pt] (im5) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image-plain}}; \ \end{tblr}

\end{document}

One can see there is no spaces between pictures. I tried to add baseline = (im1.center) option to the first tikz (and similar im2.center to the second tikz), this does not help. How can I arrange these tikzpictures?

And how can I add coordinate system to each picture so that I can use this in further drawing of arrows, somehow like \draw[->] (im1 cs: 0.1, 0.2) -- (im2 cs: 0.4, 0.7)? Here I assume coordinates relative to the whole image sizes.

Thank you for any help.

Alx
  • 737
  • For the coordinate system, see https://tex.stackexchange.com/q/9559/86 . For the positioning, one option is to draw everything in a single tikz picture using a matrix for the layout. If you stick with your current system, take the overlay out from each picture. – Andrew Stacey Oct 08 '21 at 05:45
  • I think you want to use the matrix of nodes functionality of tikz (or tikz-cd should also work since it's based on that). Then add space playing with row and column sep (need to check the exact name, don't have my computer). It also provides a name to each coordinate like yourmatrix-1-2, and you can even add alias to easily reference a particular node. In tikz-cd, you also have relative arrows, like \ar[r] will draw an arrow from current cell to the right cell. – tobiasBora Oct 08 '21 at 05:50

1 Answers1

1

Assuming, that you already have the layout, that you want, I have removed the overlay option. I use calc to calculate the relative coordinates within each picture - maybe there is an other smarter way.

\documentclass{article}
\usepackage{tikz, tabularray}
\usetikzlibrary{calc}
\begin{document}
\begin{tblr}{colspec={X[c]X[c]}, rows={m}, cell{2}{1}={r=2}{}}
\tikz[remember picture] \node[inner sep=0pt] (im1) at (0,0)  {\includegraphics[width=0.4\textwidth]{example-image-a}}; &
\tikz[remember picture] \node[inner sep=0pt] (im2) at (0,0)    
{\includegraphics[width=0.4\textwidth]{example-image-b}}; \\[1cm]
\tikz[remember picture] \node[inner sep=0pt] (im3) at (0,0) {\includegraphics[width=0.4\textwidth]{example-image-c}}; &
\tikz[remember picture] \node[inner sep=0pt] (im4) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image}}; \\
& \tikz[remember picture] \node[inner sep=0pt] (im5) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image-plain}}; \\
\end{tblr}
\begin{tikzpicture}[overlay, remember picture]
%\draw[->] ([shift={(0.1, 0.2)}] im1.south west) -- ([shift={(0.4, 0.7)}] im2.south west); %absolute coordinates
\draw[->] %relative coordinates
  ($ (im1.south west)!0.1!(im1.north west) + (im1.south west)!0.2!(im1.south east) - (im1.south west) $) --
  ($ (im2.south west)!0.4!(im2.north west) + (im2.south west)!0.7!(im2.south east) - (im2.south west) $);
\end{tikzpicture}
\end{document}

Five test images with a single arrow

Edit:

This gives the same result using relative coordinates within a scope:

   \documentclass{article}
\usepackage{tikz, tabularray}
\begin{document}
\begin{tblr}{colspec={X[c]X[c]}, rows={m}, cell{2}{1}={r=2}{}}
\tikz[remember picture] \node[inner sep=0pt] (im1) at (0,0)  {\includegraphics[width=0.4\textwidth]{example-image-a}}; &
\tikz[remember picture] \node[inner sep=0pt] (im2) at (0,0)    
{\includegraphics[width=0.4\textwidth]{example-image-b}}; \\[1cm]
\tikz[remember picture] \node[inner sep=0pt] (im3) at (0,0) {\includegraphics[width=0.4\textwidth]{example-image-c}}; &
\tikz[remember picture] \node[inner sep=0pt] (im4) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image}}; \\
& \tikz[remember picture] \node[inner sep=0pt] (im5) {\includegraphics[width=0.4\textwidth, height=2cm]{example-image-plain}}; \\
\end{tblr}
\begin{tikzpicture}[overlay, remember picture]
\begin{scope}[shift={(im1.south west)}, x={(im1.south east)}, y={(im1.north west)}]]
\coordinate (startArrow) at (0.2,0.1);
\end{scope}
\begin{scope}[shift={(im2.south west)}, x={(im2.south east)}, y={(im2.north west)}]] 
\coordinate (endArrow) at (0.7,0.4);
\end{scope}
\draw[->] (startArrow) -- (endArrow);
\end{tikzpicture}
\end{document}
  • thanks for answer, now pictures are aligned in a right way. I thought about using somehow "local" coordinates, as described here. They define "local" x and y units for picture, then it can be used to annotate inside the picture. But can we use such convenient coordinate systems (different for each picture!) between pictures? – Alx Oct 08 '21 at 06:59
  • Yes, but not at the same time - see my edit. – hpekristiansen Oct 08 '21 at 17:03
  • very nice idea in your Edit, thanks and accepted! – Alx Oct 09 '21 at 14:57