Is there a way that the pointers from the callouts use the shortest possible way to the nodes? So this is somehow an optimization problem ;-) This is my code. The callout part is copied from here.
\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetikzlibrary{positioning,chains, shapes.geometric,decorations.pathreplacing,calc,shadows.blur,shapes}
\tikzset{
add path/.style = {
decoration={show path construction,
moveto code={
\xdef\savedpath{\savedpath (\tikzinputsegmentfirst)}
},
lineto code={
\xdef\savedpath{\savedpath -- (\tikzinputsegmentlast)}
},
curveto code={
\xdef\savedpath{\savedpath .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast)}
},
closepath code={
\xdef\savedpath{\savedpath -- cycle}
}
},
decorate
},
store path/.style = {add path},
store path/.prefix code={\xdef\savedpath{}},
callouts/.style={
store path,
append after command={
foreach \target in {#1}{
($(callout)!2pt!-90:\target$)--\target --($(callout)!2pt!90:\target$)
} \savedpath
},
alias=callout
},
custom style/.style={fill=blue!20,text=},
}
\begin{document}
\begin{tikzpicture}[
[baserect/.style={text width=0.5cm,align=left,draw,},
diam/.style={diamond,draw,align=left,text width=1cm,inner sep=1.5pt,fill=yellow,text=white,minimum size=2cm},
basecirc/.style={circle,draw,align=center,text width=1.5cm},
circ/.style={basecirc,fill=blue!60,text=black}]
\node [diam] (1) {asdf};
\node [circ, right=5 of 1] (2) {asdf};
\node [diam, below=2 of 2] (3) {asdf};
\path[custom style] (3,1) node[callouts={(1.east),(2.west),(3.north west)}]{blah blah};
\end{tikzpicture}
\end{document}
Edit: My question is how I can optimize the distance from the callout to where the pointers touch the nodes. In the image the green line is shorter than the red one. How do I find the coordinate of the point of the node which is closest to the callout?



pgfpointshapebordermight solve part of your question. For instance the shortest path fromblahto the blue circle is fromblah.south eastto\pgfpointshapeborder{blue circle}{blah.south east}. For shortest paths between rectangles, they are usually from corner to corner. – Symbol 1 Sep 09 '18 at 20:11