3

When drawing tikz automata, I always omit the inital text and only use an arrow to indicate that a state is initial. To this end, I add

\tiksset[initial text={}]

to the preamble of my tex file.

This works fine so far, but when I was positioning several automata horizontally in a figure, I noticed that the initial arrow occupies to much space. You can see this phenomenon in the following picture. The red rectangle shows the bounding box.

tikz picture

I suspect that this happens because the node for the text is still there and has a nonnegative size. However, I would like to have the bounding box start where the arrow starts. Does anyone know how to achieve this without changing the bounding box by hand? Tanks!

The picture above results from the following code.

    \documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata}
\tikzset{initial text={}}

\begin{document}

\begin{tikzpicture}
    \node[state, initial] {};
    \draw[red, dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}

\end{document}

1 Answer 1

2

It's because when you clear the text of the initial node you don't actually decrease the node size. I've added a draw to the node options to make it obvious that your guess is correct:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata}
\tikzset{initial text={}}
\makeatletter
\tikzstyle{initial by arrow}=   [after node path=
{
  {
    [to path=
    {
      [->,double=none,every initial by arrow]
      ([shift=(\tikz@initial@angle:\tikz@initial@distance)]\tikztostart.\tikz@initial@angle)
          node [shape=rectangle,anchor=\tikz@initial@anchor,draw] {\tikz@initial@text}
        -- (\tikztostart)}]
    edge ()
  }
}]
\makeatother

\begin{document}

\begin{tikzpicture}
    \node[state, initial] {};
    \draw[red, dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}

\end{document}

enter image description here

Instead of draw you can put an inner sep=0 which is a good approximation, or delete the node or add overlay to keep the node but not include it in the bounding box.

4
  • Thank you! Where do you guys learn that stuff? ;)
    – Dan
    Apr 30, 2013 at 14:18
  • @Dan Heheh, Ctrl+F and keep pressing F3 a few thousand times helps.
    – percusse
    Apr 30, 2013 at 14:36
  • 1
    Wouldn’t it be easier to just replace shape=rectangle with shape=coordinate there (or just replace node with coordinate)? A crude fix without messing with the code would be [every initial by arrow/.append style={anchor/.append style={shape=coordinate}}]. Apr 30, 2013 at 14:41
  • @Qrrbrbirlbel Sure, why not? But I think best is to define a new initiall or whatever and use that anyway since appending style is also messing with the code. That library is rather old.
    – percusse
    Apr 30, 2013 at 14:56

You must log in to answer this question.

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