6

I'm trying to use tikzset with multiple arguments. I've tried to follow the instructions here, but it's not working (error is

ERROR: Illegal parameter number in definition of \pgfkeys@temp

). Here is my latex code

\documentclass[tikz]{standalone}
%\tikzset{newbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
%    label={[align=left,shift={(-12ex,3.5ex)}]south east:#1,north
%      west:{\color{red} #2}}} n args={2}}
\tikzset{oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
    label={[align=left,shift={(-12ex,3.5ex)}]south east:{\color{blue}#1}}}}
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-1,-1) (working) {};
%\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}

This will compile, but when I uncomment things, it breaks. I want newbox to take 2 arguments. Please recognize I'm not particularly skilled with tikz - there seem to be multiple ways to do everything, so I've picked up bits and pieces, but never had time to seriously try to understand the whole manual.

Joel
  • 2,429

2 Answers2

6

You're after style 2 args, as opposed to just style.

\documentclass[tikz,border=3mm]{standalone}
\tikzset{newbox/.style 2 args={
              draw, rectangle, inner sep = 1.5em, fill=white,
              label={[blue,align=left,shift={(-12ex,5.5ex)}]south east:#1},
              label={[red]north west:{#2}}
               },
    oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
    label={[align=left,shift={(-12ex,3.5ex)}]south east:{\color{blue}#1}}}}
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-1,-1) (working) {};
\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}

enter image description here

Torbjørn T.
  • 206,688
3

Here is the more refined definition.

\documentclass[tikz]{standalone}
\tikzset{newbox/.style n args=2{draw, rectangle, inner sep = 1.5em, fill=white,
    label={[align=left,anchor=south east]south west:#1},
    label={[align=left,anchor=north east,text=blue]north west:#2}},
    %
    oldbox/.style={draw, rectangle, inner sep = 1.5em, fill=white,
    label={[align=left,anchor=south east,text=blue]south west:#1}}
    }
\begin{document}
\begin{tikzpicture}
\node [oldbox={$\alpha$}] at (-2,-2) (working) {};
\node [newbox={a}{b}] at (0,0) (fails) {};
\end{tikzpicture}
\end{document}

enter image description here

  • just checking - was it a typo to have south east and then south west immediately after? Is the east part getting obliterated? – Joel Sep 29 '15 at 11:31
  • @Joel: It depends on where you want that label. I did not understand the requirement. So I just showed how you can avoid those shift commands there. The east part is not obliterated. –  Sep 29 '15 at 12:20