I am using TikZ to draw some graph drawings (with nodes and directed edges/paths). I have two nodes and an arrow pointing from one node to another. I have made a macro called \pathedge
so I can use these arrows repeatedly, but its giving me some trouble. Whenever I put an xshift
or a yshift
option before any of the nodes on the \draw command it gives me an error. I am pretty sure it has something to do with using brackets '[' ']' in a \def
macro but I don't know how to fix it. Here's the minimal code example:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{tikz}
\def\conn{\draw[arrows=->, black!50, thick]}
\newcommand{\pathedge}[4]{
\def\startn{#1}
\def\endn{#2}
\def\startnopts{}
\def\endnopts{}
\ifstrequal{#4}{NE_TO_SW} {
\def\startn{[yshift=-1ex]#1.west}
\def\endn{[xshift=1ex]#2.north}
} {}
\conn (\startn) to node[shape=circle, fill=white, inner sep=0.5pt, font=\sffamily\footnotesize]{#3} (\endn);
}
\begin{document}
\begin{tikzpicture}[scale=1,innode/.style={draw, shape=circle,ultra thick,black}]
\node[innode] (1) at (2,2) {1};
\node[innode] (2) at (4,4) {2};
\pathedge{2}{1}{A}{NE_TO_SW}
\end{tikzpicture}
\end{document}