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 would like to "reuse" some nodes' labels, as in example below

\documentclass[a4paper,12pt,oneside,titlepage]{report}  
\usepackage{tikz}  
\usetikzlibrary{positioning}  

\tikzset{  
    label node/.style = {  
        rectangle,   
        minimum size = 6mm,  
        rounded corners = 2mm,  
        very thick,  
        draw = black!50,   
        top color = white,  
        bottom color = black!20,  
        font = \sffamily,   
        anchor = east,  
    }  
}  
\begin{document}        
    \begin{tikzpicture}[line width = 1pt]  
        \node(A) [label node] at (-1, 0) {Node A};
        \node(B) [label node] at (2, 0) {A.label};
    \end{tikzpicture}  
\end{document}

So, instead of having "A.label" as label for node B, I want "Node A" to be its label without writing it explicitly, i.e. "take" the label text from the node A.

share|improve this question
2  
Note that you talk about the node content aka. text. There is also a label option which adds external labels outside the node. At first this confused me. Why do you not store the content in a macro and use the same macro for every node? –  Martin Scharrer Apr 17 '12 at 14:35
    
Yes, you're right. I just figured out the same solution. –  Oleksandr Apr 17 '12 at 14:39
    
@MartinScharrer: "Label text" seems to be the official TikZ nomenclature, at least judging by the error message "A node must have a (possibly empty) label text" you get if you forget the {}. But you're right, it's confusing that there's also a label key. –  Jake Apr 17 '12 at 14:40
2  
I think that the macro solution is best since you are going to have to add the information to B to say "take the text from A" and for that many keystrokes, it's as easy to just define an auxiliary macro. –  Loop Space Apr 18 '12 at 13:24
1  
Having said that, you could use one of the techniques in tikzstyle default node text with fill color to automatically add the text once it is saved. (Either way, if the inference from your comment is correct that you have a solution, please add your own answer with a short example so that it's clear that this problem has been solved.) –  Loop Space Apr 18 '12 at 13:27
show 2 more comments

1 Answer

There is AFAIK no possibility provided by TikZ for this. The node content is not stored and is also processed as box directly. I would simply use a macro which holds the content and can be reused:

\documentclass[a4paper,12pt,oneside,titlepage]{report}  
\usepackage{tikz}  
\usetikzlibrary{positioning}  

\tikzset{  
    label node/.style = {  
        rectangle,   
        minimum size = 6mm,  
        rounded corners = 2mm,  
        very thick,  
        draw = black!50,   
        top color = white,  
        bottom color = black!20,  
        font = \sffamily,   
        anchor = east,  
    }  
}  
\begin{document}        
    \begin{tikzpicture}[line width = 1pt]
        \def\LabelA{Node A}
        \node(A) [label node] at (-1, 0) {\LabelA};
        \node(B) [label node] at (2, 0) {\LabelA};
    \end{tikzpicture}  
\end{document}
share|improve this answer
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.