Labelling tikz nodes AND edges
1,644
As TikZ already has already a label
option (see section 16.10 The Label and Pin Options in the pgfmanual) you can not define your own style calling it label
(moreover with a different aim).
Related videos on Youtube
Author by
user21497
Updated on December 17, 2020Comments
-
user21497 almost 3 years
The following is a snippet of the original. It works..,
\documentclass[12pt]{article} \usepackage{tikz} % drawing support \usetikzlibrary{trees,arrows,decorations.markings} \definecolor{darkgreen}{rgb}{0,.5,0} \begin{document} \begin{tikzpicture}[yscale=-1,scale=1,label/.style={postaction={decorate,decoration={ markings, mark=at position .5 with \node #1;}} }] \node at (0,0) (node0) [inner sep=0pt,minimum width=1mm,circle,draw=blue] {1}; % node#1 \end{tikzpicture} \end{document}
The label style is primarily for edges which don't appear in the snippet above. However, I'd like to label the nodes, too: change the \node line to:
\node at (0,0) (node0) [inner sep=0pt,minimum width=1mm,circle,draw=blue] [label=60:X] {1}; % node#1
which is intended to put the letter "X" at a 60 degree angle from the node.
Tikz then "blesses" me with a
Package tikz Error: A node must have a (possibly empty) label text.
I've tried numerous combinations of [] {} etc, and haven't gotten the code to work.
-
Claudio Fiandrino about 10 yearsI think to call
label
a custom style is bad as there's already alabel
: check on the manual. A more correct way (at least it works ;) ) to do that (I mean using the library markings) is my style insert node. -
user21497 about 10 years\tikzstyle{edgelabel}=[style={postaction={decorate,decoration={ markings, mark=at position .5 with \node #1;}} }]
-
Claudio Fiandrino about 10 yearsDon't use the obsolete
tikzstyle
, see Should \tikzset or \tikzstyle be used to define TikZ styles?
-