# Add label to flowchart nodes

I need to add a "label" to nodes in a flowchart with tikz, preferably in the top left corner. See picture: the text in red is where I need it.

This is because each block should have a "label" so I can refer to it elsewhere in the text and in other flowcharts (expanding nodes).

-
Welcome to tex.sx! Note that it is unusual around here to have any greeting. A suggestion: Change your username to something more telling than "user3822". –  lockstep Feb 25 '11 at 21:36

You can add the label as second node over the other one.

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\node [draw,rounded corners=2pt,fill=blue!20,inner sep=1em] (A)
{Node content};

\node [anchor=north west,font=\tiny\color{red}] at (A.north west)
{label};

\end{tikzpicture}
\end{document}


There is also the label key (see the pgfmanual section 16.10 The Label and Pin Options, page 194) which exists for adding labels like that. Unfortunately the label can only be on the outside of the node. I didn't found out how to place them inside yet. A negative label distance seems to have no effect.

\node [draw,rounded corners=2pt,fill=blue!20,inner sep=1em,label={[red]north west:\tiny Label outside}] (A)
{Node content};

-
Thank you very much, it works perfectly! I actually tried the anchor command, but it did not work :( I must have messed up the arguments? Anyway, now it works, THANK YOU :) –  annadifrancia Feb 26 '11 at 12:24

You could overlay the box

 \documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[minimum width=3cm, minimum height=2cm, rounded corners,draw,fill=blue!30] (a) {Box content};
\node[overlay, xshift=1pt,anchor=north west] at (a.north west) {Label};
\end{tikzpicture}
\end{document}


-
That code produces exactly the same output without overlay. In fact, the effect of overlay is just that everything within the current scope is not taken into consideration when the bounding box of the current picture is computed (p.199 of the manual). –  Caramdir Feb 25 '11 at 21:57