# How to avoid superfluous space in the initial state of a tikz automaton

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.

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}

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}

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.

• Thank you! Where do you guys learn that stuff? ;) – Dan Apr 30 '13 at 14:18
• @Dan Heheh, Ctrl+F and keep pressing F3 a few thousand times helps. – percusse Apr 30 '13 at 14:36
• 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}}]. – Qrrbrbirlbel Apr 30 '13 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 '13 at 14:56