表格中的 Tikzpictures 带有标签和箭头

表格中的 Tikzpictures 带有标签和箭头

我需要排列几张图片,然后给每张图片贴上标签,并在一些标签(相同和不同的图片)之间画箭头。我认为这可以用tikzpictures in来完成tabular。到目前为止,我有这个 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}

可以看到图片之间没有空格。我尝试baseline = (im1.center)向第一个添加选项tikz(与im2.center第二个类似tikz),但这没有帮助。我该如何排列这些 tikzpictures?

我怎样才能将坐标系添加到每张图片中,以便我可以使用它来进一步绘制箭头,不知何故\draw[->] (im1 cs: 0.1, 0.2) -- (im2 cs: 0.4, 0.7)?在这里我假设坐标相对于整个图像大小。

感谢您的任何帮助。

答案1

假设您已经有了想要的布局,我已删除该overlay选项。我用calc它来计算每张图片内的相对坐标 - 也许还有其他更聪明的方法。

\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}

带有单箭头的五张测试图像

编辑:

在一定范围内使用相对坐标可以得到相同的结果:

   \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}

相关内容