I want to draw a graph like in the second picture of the following code:
\documentclass{article}
\usepackage{mathptmx}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes,graphs,graphs.standard,quotes}
\usepackage{calc}% http://ctan.org/pkg/calc
\usepackage{ifthen}
\begin{document}
% This one works
\begin{tikzpicture}
\foreach \x in {1,...,5}
{ \node[circle,draw] (\x 1) at (0,\x) {\x};
\node[circle,draw] (\x 2)at (2,\x) {\x};
\ifthenelse{\NOT 4 = \x \AND \NOT 7 = \x}{\draw (\x 1) -- (\x 2);}{} % (*)
}
\end{tikzpicture}
% This one does not work with line (*)
\begin{tikzpicture}
\tikzstyle{vertex}=[circle,fill=blue!15,draw,minimum size=17pt,inner sep=0pt]
%See TikZ documentation! (Section 19, graphs)
\graph[circular placement, radius=4cm, group polar shift=(360/5:0),
nodes={circle,draw,vertex}] {
\foreach \x [evaluate=\x as \sx using int(\x+1)] in {0,...,4} {
\foreach \y in {\x,...,4} {
\x -- \y;
%\ifthenelse{\NOT 4 = \x \AND \NOT 7 = \x}{\draw (\x 1) -- (\x 2);}{} % (*)
};
};
};
\end{tikzpicture}
\end{document}
It uses the TikZ graph library. As you might guess, I want to label the edges dependent on what \x
and \y
are in the for loop. So I need an If-Then-Else
statement and came to this answer: https://tex.stackexchange.com/a/45907/52709.
I copied the code, it is the first picture and it works.
But applying the same \ifthenelse
-line to my code (commented out), produces an error at that line:
! Undefined control sequence.<argument> \NOT 4 = \x \AND \NOT 7 = \x }
and also
! Illegal parameter number in definition of \tikz@lib@graph@name.
at the end of the graph defintion (};
).
Isn’t it possible to use something like \ifthenelse
inside such a graph definition?
How can I achieve what I need?
\ifthenelse
? Is there another way to do it?\x
with 4 an 7, but that doesn't makes much sense, and it does not use\y
.