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.

Is there a TikZ style attribute for adding default text to a node? For instance, I want to be able to do something like the following:

\begin{tikzpicture}[%
  stuff/.style={%
    draw,
    text=Bla bla
  },
]

\node at (0,0) [stuff] {};
\node at (0,1) [stuff] {};
\node at (0,2) [stuff] {};
\node at (0,3) [stuff] {};
\end{tikzpicture}

to produce a picture containing 4 nodes, each with the text "Bla bla". I want to be able to create nodes with the same text without having to add it manually.

share|improve this question
    
I once looking into something like that. I can't remember the final outcome just now, but it wasn't very positive. This requires some serious hacking of the TikZ internals. –  Martin Scharrer Nov 13 '11 at 19:53
    
As a workaround, you could perhaps use a loop to make the nodes, iterating over coordinates. –  Torbjørn T. Nov 13 '11 at 20:02
    
@TorbjørnT.: Yes, that would be the most reasonable solution in most instances, but I've encountered numerous situations where that's not possible because the nodes are not placed in areas where a \for can be used. –  gablin Nov 13 '11 at 20:53
    
For yet another alternative solution see Default node text with fill color –  percusse Mar 22 '12 at 11:45
add comment

1 Answer 1

up vote 13 down vote accepted

It's not exactly what it was designed for, but you can add fixed text to the font parameter:

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}[%
  stuff/.style={%
    draw,
    font={A}}
]

\node at (0,0) [stuff] {};
\node at (0,1) [stuff] {};
\node at (0,2) [stuff] {};
\node at (0,3) [stuff] {};
\end{tikzpicture}

\end{document}

output of code

share|improve this answer
8  
If there were a "sneaky" badge, this would be my candidate for it. –  Loop Space Nov 13 '11 at 21:53
    
Also see tikzstyle default node text with fill color which provides a detailed explanation of the "hooks" available. –  Peter Grill Mar 22 '12 at 15:17
    
Do you try align=right,font={$x+2$\\very bad idea }? –  Alain Matthes Mar 22 '12 at 22:48
    
@Altermundus Well, it's already a trick, so expecting to put a \\ inside is asking for trouble. :) –  Alan Munn Mar 23 '12 at 0:34
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.