6

I am trying to annotate bent arcs of a graph. There should be a link from the bent arc to the text of the annotation. Moreover the link should be perpendicular to the tangent to the bent arc.

Here is an example of code trying to do that, but one would have to modify the line

($(midp-\i)$) -- +(0.33cm,0.33cm) node[above]

This code is an adaptation of answers to the following questions: tikz: How to pass a list as a parameter of a tikz macro and use it in a foreach inside the macro and anchor point on a self loop (to draw a line from that anchor point)

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}

% #1: list of nodes label, #2: list of arcs annotation
\def\graphcircuit#1#2{
\foreach[count=\n] \v in {#1}; % count the number of elements
\pgfmathsetmacro{\r}{\n*0.2} % set the node distance from (0,0)
\pgfmathsetmacro{\b}{90/\n} % evaluate the bend angle
\foreach[count=\i, evaluate=\i as \a using (\i-1)*360/\n] \v in {#1} % write nodes
    \node [circle, draw, font=\scriptsize] (n-\i) at (\a:\r) {$\v$};
\foreach \i [remember=\i as \j (initially \n)] in {1,...,\n} % write arcs and create anchor points
    \path[->,bend right=\b] (n-\j) edge coordinate[pos=0.5] (midp-\j) (n-\i);
\foreach[count=\i] \annotation in {#2} % write annotations on each arc
    \path[draw=black!80,line width=0.6pt,dotted] ($(midp-\i)$) -- +(0.33cm,0.33cm) node[above] {\scriptsize\annotation};
}

\begin{tikzpicture}
\graphcircuit{1:5,7:2,3:0,4:0,9:1}{a,b,c,d,f}
\end{tikzpicture}

\end{document}
5

Perhaps use a pin? Might need some adjustment, but should give the basic idea:

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc}

\begin{document}
  \def\graphcircuit#1#2{%
    \foreach [count=\n] \v in {#1}; % count the number of elements
    \pgfmathsetmacro {\r} {\n*0.2} % set the node distance from (0,0)
    \pgfmathsetmacro {\b} {90/\n} % evaluate the bend angle
    \pgfmathsetmacro {\p} {360/\n}
    \foreach [count=\i, evaluate=\i as \a using (\i-1)*360/\n] \v in {#1} % write nodes
      \node [circle, draw, font=\scriptsize] (n-\i) at (\a:\r) {$\v$};
    \foreach \i [remember=\i as \j (initially \n)] in {1,...,\n} % write arcs and create anchor points
      \path [->,bend right=\b] (n-\j) edge coordinate [pos=0.5] (midp-\j) (n-\i);
    \foreach [count=\i] \annotation in {#2} % write annotations on each arc
    \node [pin={[pin edge={draw=black!80,line width=0.6pt,dotted}, font=\scriptsize]\i*\p-.5*\p:\annotation}] at ($(midp-\i)$) {};
  }%
  \begin{tikzpicture}
    \graphcircuit{1:5,7:2,3:0,4:0,9:1}{a,b,c,d,f}
  \end{tikzpicture}
\end{document}

pins

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.