Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
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. –  Ulrike Fischer 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) –  xeroc 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? –  Loop Space Jun 14 '11 at 11:07
add comment

3 Answers

up vote 6 down vote accepted

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 }
share|improve this answer
This is a very good generalized solution. –  Yiannis Lazarides Jun 14 '11 at 13:57
Thats exactly what I was searching for. Thanks –  xeroc Jun 15 '11 at 9:53
add comment

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

share|improve this answer
Oh. This solution is nice. Didn't think of that. thanks –  xeroc Jun 15 '11 at 9:52
add comment

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

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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