2

Consider the following MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
  \tikz \graph [nodes={empty nodes, fill, circle, inner sep=1pt, draw}]{
      \foreach \i in {1,...,5} { a --[bend left={2*90/5-(\i-1)*90/5}] b; }
    };
\end{document}

Graph

The result looks quite elegant, but I actually want the in and out angle of the edges to be equal. It now seems that in=180 for all edges, although the description for /tikz/bend left=<angle> in the PGF manual states

This option sets out=<angle>,in=180-<angle>,relative. If no <angle> is given, the last given bend left or bend right angle is used.

What did I do wrong?

3

Here is how bend left is defined

\tikzoption{bend left}[]{%
  \def\pgf@temp{#1}%
  \ifx\pgf@temp\pgfutil@empty%
  \else%
    \def\tikz@to@bend{#1}%
  \fi%
  \let\tikz@to@out=\tikz@to@bend%
  \c@pgf@counta=180\relax%
  \advance\c@pgf@counta by-\tikz@to@out\relax%
  \edef\tikz@to@in{\the\c@pgf@counta}%
  \tikz@to@switch@on%
  \tikz@to@relativetrue%
}

As you can see, TikZ uses TeX's arithmetics to calculated the in factor. Therefore you cannot pass a mathematical expression to it.

Instead, you should do the arithmetics yourself, such as the following

  \tikz \graph [nodes={empty nodes, fill, circle, inner sep=1pt, draw}]{
      \foreach \i in {1,...,5} {
          a --[
              /utils/exec={\pgfmathsetmacro\bendangle{2*90/5-(\i-1)*90/5}},
              bend left=\bendangle
          ] b; }
    };

Update

@Ignasi suggests the following

\foreach \i [evaluate=\i as \bendangle using {2*90/5-(\i-1)*90/5}] in {1,...,5}
    { a--[bend left=\bendangle] b;}

And then I found the following works

\foreach \i [evaluate={\bendangle=2*90/5-(\i-1)*90/5;}] in {1,...,5}
    { a--[bend left=\bendangle] b;}

If you have \usetikzlibrary{math}, then the following also works

  \foreach \i in {1,...,5} {
      a --[
          evaluate={\bendangle=2*90/5-(\i-1)*90/5;},
          bend left=\bendangle
      ] b; }

For the first case, the key is handled by /pgf/foreach/evaluate and then \pgffor@assign@@parse@old.

For the second case, the key is handled by /pgf/foreach/evaluate and then \pgffor@assign@@parse.

For the third case, the key is handled by /tikz/evaluate and then \tikz@math.

  • 1
    or \foreach \i [evaluate=\i as \bendangle using {2*90/5-(\i-1)*90/5}] in {1,...,5}{ a--[bend left=\bendangle] b;} – Ignasi Mar 28 '17 at 17:35
  • @Ignasi Interesting! I found evaluate={\bendangle=2*90/5-(\i-1)*90/5;} also works, and is compatible with \tikzmath. – Symbol 1 Mar 28 '17 at 17:46

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.