
Ich versuche, \pgfmathifthenelse
mit dem Befehl einen Knoten in meinem Diagramm zu platzieren tikz
, aber es tritt weiterhin dieser Fehler auf:
„Unvollständig \iffalse“
Hier ist mein Code:
\begin{tikzpicture}
\def \n {4}
\def \hradius {2cm}
\def \vradius {1.2cm}
\def \nradius {0cm}
\def \lengths {3,4,6}
\def \degree {3}
\node (u) at (0,{2*\vradius}) {$\bullet$};
\node (v) at (0,{-2*\vradius}) {$\bullet$};
\node at (0,{2.2*\vradius}) {$u$};
\node at (0,{-2.2*\vradius}) {$v$};
\draw[>=latex] (v.center) -- (u.center) node [midway,left]{{$1$}};
\foreach [count=\i, evaluate=\i as \k] \s in \lengths {
\pgfmathparse{\s-1}
\edef \l {\pgfmathresult}
\pgfmathparse{\k-2}
\def \xtmp {\pgfmathresult}
\pgfmathparse{\xtmp+1}
\edef \xfactor {\pgfmathresult}
\pgfmathparse{\pgfmathifthenelse{\xtmp=0}{\xfactor {\xtmp}}\pgfmathresult
\edef \xfinal {\pgfmathresult}
\foreach \i in {1,...,\l}{
\pgfmathparse{1/\s}
\def \inverse {\pgfmathresult}
\node (\s\i) at ({(\k-2)*\hradius},{((4*\vradius)*\inverse*\i)-2*\vradius}) {\k};
}
}
\end{tikzpicture}
Weiß jemand, wo das Problem liegt?
Antwort1
Einige Fragen:
- Bei der Zeile mit hat eine Klammer gefehlt
pgfmathifthenelse
. - Alle Ihre Befehle können umgeschrieben werden, um eine Variable inline festzulegen, anstatt zu verwenden
\pgfmathresult
.\pgfmathparse
tut das, aber Sie können verwenden\pgfmathsetmacro<VARIABLE>{<CODE>}
Sie können das \pgfmathifthenelse
Umschreiben also wie folgt beheben:
\pgfmathsetmacro\xfinal{(\xtmp==0?(\xfactor):\xtmp)}
was
\pgfmathsetmacro\xfinal{(<TEST>?(<TRUE>):<FALSE>)}
Ausgabe
Code
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\n{4}
\def\hradius{2cm}
\def\vradius{1.2cm}
\def\nradius{0cm}
\def\lengths{3,4,6}
\def\degree{3}
\node (u) at (0,{2*\vradius}) {$\bullet$};
\node (v) at (0,{-2*\vradius}) {$\bullet$};
\node at (0,{2.2*\vradius}) {$u$};
\node at (0,{-2.2*\vradius}) {$v$};
\draw[>=latex] (v.center) -- (u.center) node [midway,left]{{$1$}};
\foreach [count=\i, evaluate=\i as \k] \s in \lengths {%
\pgfmathsetmacro\l{\s-1}
\pgfmathsetmacro\xtmp{\k-2}
\pgfmathsetmacro\xfactor{\xtmp+1}
\pgfmathsetmacro\xfinal{(\xtmp==0?(\xfactor):\xtmp)}
\foreach \i in {1,...,\l}{%
\pgfmathsetmacro\inverse{1/\s}
\node (\s\i) at ({(\k-2)*\hradius},{((4*\vradius)*\inverse*\i)-2*\vradius}) {\k};
}
}
\end{tikzpicture}
\end{document}