I'd like to draw some linear Systems with tikz. The problem is the orientation of the Systems. Some have

  • input on left - output on right
  • input on right - output on left
  • input above - output below
  • input below - output above

So to handle all the variations with a single \command, i'd like to use the arguments

  • ud (up down)
  • du (down up)
  • lr (left right)
  • rl (right left)

So what I need is a switch in Latex to define the Orientationparameter.



Command: drawSYS
 \switch #2
  \case 'lr'
   \def\ORIENTA left
   \def\ORIENTB right
  \case 'rl'
   \def\ORIENTA right
   \def\ORIENTB left
 \node[anchor=\ORIENTA,\ORIENTB=1cm] () {foobar};

Is this even possible in Tex?

Thanks for your help.

  • 1
    I don't really understand what you're asking exactly. Maybe give an example of what you'd like the macro to look like and what it should expand to depending on its arguments.
    – TH.
    Jun 14 '11 at 9:16
  • Naturally it is possible. You only need to look at the documentation of tikz and the use of words like "left" "right" "north" "above" .... Or take the optional arguments [t], [b] of tabular. Jun 14 '11 at 9:33
  • I'd like to have a single macro which has a single argument to define weather it is left(anchor right) or right(anchor left) (+ the combinations with up/down) Jun 14 '11 at 10:47
  • I'm not sure that I completely understand, but it seems as though what you'd like is to specify a single option which did, say, anchor=east,rotate=90. Or anchor=east,xscale=-1. That's easy enough to do using styles. Does that sound like what you want? Jun 14 '11 at 11:07

This is a general "cases" type command that is also usefull ouside the tikz community ;-). It returns an \ifcase <pos> in a list

    \edef\@testlist{\zap@space#1 \@empty}%
    \edef\@invalue{\zap@space#2 \@empty}%

    \ifchoice{ud, du, lr, rl}{#2}%
       %-------------------- 0  = ud
    \or%-------------------- 1  = du
    \or%-------------------- 2  = lr
    \or%-------------------- 3  = rl
    \else%------------------ 99 = default
    (#1)(#2)[\ORIENTA][\ORIENTB]}%--- Test output

   \drawSYS{xxx}{ rl }
  • This is a very good generalized solution. Jun 14 '11 at 13:57
  • Thats exactly what I was searching for. Thanks Jun 15 '11 at 9:53

You can use the pgfkeys .is choice option. It looks like you don't actually want to execute pieces of code depending on the choice, but merely set styles, which makes this approach the obvious choice. Note that you could also execute code pieces by using \pgfkeys{/tikz/orientation/lr/.code=<code>}:




\tikzset{orientation/.is choice,

    \node [orientation=#1] {#2};

\begin{tikzpicture}[every node/.style=draw]
\draw [fill=red] (0,0) circle [radius=3pt];


tikz .is choice

  • Oh. This solution is nice. Didn't think of that. thanks Jun 15 '11 at 9:52

The xparse package has a lot of argument dependent macro-defining capabilities. I don't know if it supports string comparison though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.