3

I would like to define a macro that draw a triangle nested in a triangle. I already have a triangle macro using TikZ that draws a nice triangle given a size. For simplicity,

\tr{4}

Will create a triangle of size 4. What I would like is a macro for nested triangles that calls tr twice, once with the size, and then again with half the size.

\newcommand{\trNest}[1]{\tr{#1} \tr{ {#1} / 2}}

There is just one thing, / does not perform division. How can I pass the result of dividing argument by a number in LaTeX?

6
  • 1
    Would be nice if you created a minimal example with the \tr macro you've defined. Commented Sep 18, 2013 at 18:23
  • 1
    Have you tried \tr{\numexpr #1/2\relax}? Commented Sep 18, 2013 at 18:29
  • 1
    Depending on how you defined the \tr macro (and hence would be good to have a MWE as per @TorbjørnT.'s comment), you could just use tikz's scale = 0.5 option, or use 0.5*#1 (with the calc package), or use pgfmath/\pgfmathsetmacro to perform numerical computation. Commented Sep 18, 2013 at 18:38
  • @Peter Grill. Your answer of using 0.5*_ works great. Thank you! Commented Sep 18, 2013 at 18:48
  • @Torbjorn T. I am confused. What would you like to see? I can upload the macro I used, if that would help. Commented Sep 18, 2013 at 18:50

1 Answer 1

4

Depending on how you defined the \tr macro, there are different options that could be employed including:

  • tikz's scale = 0.5 option, or
  • use x=0.5cm, y=0.5cm to change the x and y unit vectors, or
  • use 0.5*#1 (with the calc package), or
  • use \pgfmathsetmacro to perform numerical computation.

Which one makes more sense would depend on the specifics of the \tr macro, and hence would be good to have a MWE as requested in the comments.

You must log in to answer this question.

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