0

I wish to to use a command in the style section of a tikz draw command so that I can easily parameterize the relative positioning of nodes in a drawing package that I'm creating.

In the example:

\usepackage{tikz}

\begin{document}
\end{document}

\newcommand{\XX}{above left = of a}

\begin{tikzpicture}
    \node [circle,draw] (a) {};
    \node [circle, draw, {\XX}] () {};
\end{tikzpicture}

I get the error:

Package pgfkeys Error: I do not know the key '/tikz/above left = of a' and I am going to ignore it. Perhaps you misspelled it. \node [circle, draw, {\XX}]

How can I use a command in the style section of a tikz command?

1
  • Welcome to TSE. Please post a Minimal Working Example, instead of a code snippetl. Apr 10, 2020 at 5:53

1 Answer 1

1

Welcome! You can use the key style/.expanded for that.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}

\newcommand{\XX}{above left = of a}

\begin{tikzpicture}
    \node [circle,draw] (a) {a};
    \node [circle, draw, style/.expanded=\XX] (b) {b};
\end{tikzpicture}
\end{document}

enter image description here

Of course, the more TikZy way of doing this is not to use a macro but a style.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}


\begin{tikzpicture}[XX/.style={above left = of a}]
    \node [circle,draw] (a) {a};
    \node [circle, draw, XX] (b) {b};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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