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 have an automaton in tikz and would like to have some text within a triangle of the right size. How can I do that efficiently?

I have tried using a regular polygon, but I can't shrink it to the right size: minimum height and minimum size have no effect. So is there any parameter that controls the size?

     \node[state,inner sep=0pt,minimum size=.3cm] at (0,0) (init) {};
     \node[state,inner sep=0pt,minimum size=.3cm] at (-5,-1.3) (idelta)
    \node[draw,minimum height=.5cm,regular
    polygon,regular polygon sides=3] at (-5,-1.3) {foo};

     (init)+(0,.5cm) edge (init)
     (init) edge node[] {bar} (idelta);
share|improve this question
inner sep=0 maybe? –  percusse Jul 8 '13 at 17:49
inner sep=0 did make the triangle a bit smaller, but minimum height, minimum size still has no effect. I do need the triangle much smaller. scale does the trick, but also shrinks the text. –  DaveBall aka user750378 Jul 8 '13 at 17:52
It can't be smaller than the text box.Unless you make a negative inner sep but that has other complications. Or you can change the apex angle to a large value such that it gets wider and shorter –  percusse Jul 8 '13 at 17:53
Remove the node text and add a label: label=center:foo. But you have to take care that the shape border doesn’t overlap with the text as it doesn’t do this automatically anymore, similar to using a negative inner sep. –  Qrrbrbirlbel Jul 8 '13 at 17:59
@Qrrbrbirlbel: thanks a lot, useful as always :) –  DaveBall aka user750378 Jul 8 '13 at 18:39
show 3 more comments

3 Answers

up vote 3 down vote accepted

I think this is small enough via kerning (which makes the box quite smaller horizontally) :-)

   \node[draw,minimum size=0cm,inner sep=0,regular polygon,regular polygon sides=3] at (-5,-1.3) {\kern-0.15emfoo\kern-0.15em};
   \node[draw,minimum size=0cm,inner sep=0,regular polygon,regular polygon sides=3] at (-5,-1.3) {\kern-0.5emfoo\kern-0.5em};

enter image description here

share|improve this answer
yes they are math spaces, sorry :-) but they are too handy. –  percusse Jul 8 '13 at 19:26
kerning's a good idea, since the triangle grows with the text (+1). But I favor the tikz solution since I can position the text better within the triangle. –  DaveBall aka user750378 Jul 8 '13 at 20:06
@DaveBallakauser750378 This is a Tikz solution. –  percusse Jul 8 '13 at 20:09
Even though I used a different solution (see my own answer), I've accepted your answer, since it is a simple Tikz solution... –  DaveBall aka user750378 Jul 11 '13 at 19:36
add comment

I don't know tikz, but I'm sure one of these formulations can be stuck into a tikz picture.

  \setlength\triwidth{\widthof{#1\ }}%
  \stackengine{-.4\triwidth}{#1\ }%
  \setlength\triwidth{\widthof{\ #1\ }}%
  \stackengine{-.2\triwidth}{\ #1\ }
\parskip 1ex


enter image description here

share|improve this answer
Using \widthof is a good idea - and stackengine anyways ;) –  DaveBall aka user750378 Jul 8 '13 at 20:07
add comment

Using Qrrbrbirlbel comments and answer How can I set the TikZ label anchor explicitly?, I got the following solution:

        \node[inner sep=0,draw,minimum height=#3,regular
        polygon,regular polygon
        sides=3,label={[anchor=south,inner ysep=.03em]below:\footnotesize #4},anchor=north]
        at (#1,#2) {};


\tikzset{anchor/.append code=\let\tikz@auto@anchor\relax}

in the preamble.

triangle-example, e.g. for trees

share|improve this answer
The label is just a node, so you can use inner ysep=<something smaller then .3333em as well. (If you use this often, you might use an extra style and/or the every label style.) –  Qrrbrbirlbel Jul 8 '13 at 19:53
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.