I have an external picture and I want to put some labels on it. The code below works fine, but I want to automate the calculation of the vertical label positions in case of resizing the imported external figure. Is there a way to obtain the height of the node probe
or the image itsels and to use that in the positioning inside [above right = 2cm and 1cm of probe]
, e.g. something like [above right = 0.25*\imageheight and 1cm of probe]
?
\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (probe) at (0,0){\includegraphics[width=.25\textwidth]{test}};
\node[right = 1cm of probe](adhesivelabel) at (probe.east) {Adhesive};
\node[above right = 2cm and 1cm of probe](adherent1label) at (probe.east) {Adherent 1};
\node[below right = 2cm and 1cm of probe](adherent2label) at (probe.east) {Adherent 2};
\draw[->] (adhesivelabel.west) -- (probe);
\draw[->] (adherent1label.west) -- (probe.east |- adherent1label.west);
\draw[->] (adherent2label.west) -- (probe.east |- adherent2label.west);
\end{tikzpicture}
\end{document}
Best Answer
First solution with
calc
TiKZlibrary
:Second solution with
\tcbsetmacroto{width|height}
commands fromtcolorbox
skin
library: