I wish to add a label above a node that already contains a label.

\begin{tikzpicture}[scale=0.8,every node/.style={draw=black,circle}]
    \node (a) at (0,0) {a};
    \node (b) at (2,0) {b};
    \draw[->] (a) to (b);

The markup above will give me this:


But I want something like this:


Is there any easy way to solve this? I am not looking for solutions using \tikzlibrary{background}


Actually, tikz nodes have text inside and labels outside:



\begin{tikzpicture}[scale=0.8,every node/.style={draw=black,circle}]
    \node[label={\small 1/16}] (a) at (0,0) {a};
    \node (b) at (2,0) {b};
    \draw[->] (a) to (b);

  • 1
    Let me noted: since label is node, its features is influenced by options determined in every node style. To see this, change every node/.style={draw=black,circle} to every node/.style={draw, red,circle} ... Therefore it is sensible in similar cases to define labels' style with something as every label/.append style={rectangle, font=\small}.
    – Zarko
    Apr 20 '17 at 20:40
  • 3
    Excellent. We can also use \node[label={[xshift=1em, yshift=-1em] XYZ}] to shift the label positions. Dec 25 '20 at 8:15

A PSTricks solution using the pst-node (for the drawing itself) and xfp packages (for the floating point calculations):



\def\labelSep{\fpeval{28.75*\radius+3.375}} % found by experimenting

% parameters


% change `0.35` in the calculation of the height of the bounding box
% according to the contents on top of the node
  \uput{\labelSep pt}[90](A){\small\texttt{1/16}}



Notice that all you have to do is choose the values of the parameters and the drawing (including the bounding box) will be adjusted accordingly.

  • 1
    – user2478
    Dec 11 '14 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.