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 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).

enter image description here

share|improve this question
2  
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
add comment

2 Answers

up vote 4 down vote accepted

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}

Result

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};
share|improve this answer
    
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
add comment

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}

enter image description here

share|improve this answer
1  
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
add comment

Your Answer

 
discard

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.