6

When using every edge/.append style = {thick}, Mod doesn't work as intended. Not sure, if the problem is what I am infering or is something else.

For example, consider

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\tikzset{
  every edge/.append style = {thick}% commenting this solves the problem
}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\node (table) {};
\foreach \i in {1,...,5}{
  \pgfmathparse{mod(\i*72+18,360)}
  \node[] at (\pgfmathresult:3cm) (table) (p\i) {$F_\i$};
  \pgfmathparse{mod(\i*72+54,360)}
  \node[] at (\pgfmathresult:2cm) (table) (c\i) {$C_\i$};
}

\foreach \i in {1,...,5}{
  \pgfmathparse{Mod(\i-2,5)+1}
  \draw[->, red] (p\i) edge (c\pgfmathresult);
  \node[right=.5cm of p\i] {\pgfmathresult};% see the result of the operation, they are random numbers
}
\end{tikzpicture}
\end{frame}

\end{document}

This code causes problems with the Mod as it throws random numbers (at least they seem to be)

enter image description here

I added the \node[right=.5cm of p\i] {\pgfmathresult}; to see the result on the operation. Interestingly if one removes the every edge/.append style = {thick} the operation works as intended.

What am I missing? Is there a way to set the edges to be thick and to have the Mod working?

4
  • I remove everything from my original file, but in there I have some styles for edges, and wanted to add it globaly. On the way, I found that the modulo gave me error, and bring it down to what you see in the MWE.
    – adn
    Commented May 10, 2015 at 3:19
  • You should save the results in a macro as soon as possible. Between using \pgfmathparse and calling \pgfmathresult you cannot be certain that TikZ hasn't itself redefined \pgfmathresult. So try \pgfmathsetmacro{...} or after calling \pfmathparse call \edef\myresult{\pgfmathresult} before performing any thing else with either pgf or TikZ.
    – A.Ellett
    Commented May 10, 2015 at 4:00
  • 1
    That random number is .5cm in pt units. Because your \pgfmathresult is overwritten during line thickness setting. And thick setting internally does computations about line width hence also overwrites \pgfmathresult. This is a duplicate somewhere.
    – percusse
    Commented May 10, 2015 at 6:09
  • 1
    Maybe this ? tex.stackexchange.com/questions/191248/…
    – percusse
    Commented May 10, 2015 at 6:11

1 Answer 1

7

How's this

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\tikzset{
  every edge/.append style = {thick}% commenting this solves the problem
}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\node (table) {};

\foreach \i in {1,...,5}{
  \pgfmathsetmacro\myresult{int(mod(\i*72+18,360))}
  \node[] at ($(\myresult:3cm)+(table)$) (p\i) {$F_\i$};
  \pgfmathsetmacro\myresult{int(mod(\i*72+54,360))}
  \node[] at ($(\myresult:2cm)+(table)$) (c\i) {$C_\i$};
}

\foreach \i in {1,...,5}{
  \pgfmathparse{int(Mod(\i-2,5)+1)}
  \edef\myresult{\pgfmathresult}%%
  \draw[->, red,every edge/.append style={thick}] (p\i) edge (c\myresult);
  \node[right=.5cm of p\i] {\myresult};% see the result of the operation, they are random numbers
}
\end{tikzpicture}
\end{frame}

\end{document}

Resulting image (not quite sure how you wanted this to look)

enter image description here

Your syntax for the nodes is a bit confusing. I'm not sure what you intended by

\node at (<location>) (<node name>) (<node name>) {<content>};

So I modified your syntax a bit.

Also, mod will return a decimal value. You need integer values. So, I've modified that part of your \pgfmathparse computations.

Also I illustrate to safer ways to retrieve and use the values of \pgfmathparse. Do one of the following two

\pgfmathsetmacro\myresult{<computation>}

or

\pgfmathparse{<computation>}
\edef\myresult{\pgfmathresult}

The problem is that TikZ and pgf both actively use \pgfmathresult. So you want to save the value first before you do anything where you might need it.

1
  • 1
    \foreach \i[evaluate={\myresult=int(Mod(\i-2,5)+1);}] in {1,...,5}{ does the same thing but easier to read probably.
    – percusse
    Commented May 10, 2015 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .