PSTricks' \Rnode makes it easy to add annotations to a complex equation typeset by (La)TeX:

PSTricks inline \Rnode

Simply add \Rnodes around existing elements of the equation, and the mathematical typesetting is preserved. How is this achieved in TikZ, with the same simplicity?

The LaTeX code which produced the above example:



R^{\alpha \beta} - 
{1 \over 2}R g^{\alpha \beta} + 
g^{\alpha \beta} \Lambda 
\frac{8 \pi G}{c^4 \mu_0} 
  F^{\alpha}{}^{\Rnode{a}{\scriptstyle\psi}}   % <---- 1st \Rnode
  F_{\Rnode{b}{\scriptstyle\psi}}{}^{\beta} +  % <---- 2nd \Rnode
  {1 \over 4} g^{\alpha \beta} F_{\psi\tau} 
\ncbar[linecolor=blue,angle=-90,nodesep=1pt,arm=2ex]{<->}{a}{b}$ }


Actually, it is relatively easy to do with TikZ:

Place nodes with

\tikz[baseline, rememeber picture]
  \node[anchor=base, inner sep=+0pt, outer sep=+0pt] (<name>) {<text>};

The combination of baseline and anchor=base puts <text> on the already established baseline and inner sep=+0pt and outer sep=+0pt makes sure that the node (and the picture) has the same size as the actual box enclosing <text>.

Then you can use those <name>s in a TikZ path (that should be overlayed):

\tikz[remember picture, overlay]
  \draw (<name 1>) -- (<name 2>);

If you often simply connect two nodes and always the last defined you can make your life easier with the macros \Tnode and \TnodeC where the latter is like the first but also draws a path to the last node defined by the first.

If you don’t want to connect the last two nodes you give a coordinate/node name after the optional arguments of the edge.

An overview:

\Tnode[<optional node options>]{<node name>}{<node math>}


\TnodeC[<optional node options>]{<node name>}{<node math>}
                           [<optional edge options>]{<alternative target node for the edge>}

Of course, you can also use to path={<anything>} inside the <optional edge options> to overwrite anything (you don’t need to use \tikztarget or \tikzstart).

For unrelated edges, you can of course just use a separated \path as described earlier.

The \TnodeC has also a starred version where the vertical dimension of the path is taken into account. (In your case this would stretch \left( … \right) which is the reason why I used \vphantom in combination with \TnodeC* but you could also just use \bigl( … \bigr).)

It is also possible to implement a syntax where the node names are enclosed in ( and ) but that makes the code slightly larger.

For various approaches to implement \ncbar see Is there a TikZ equivalent to the PSTricks \ncbar command?. I have used my paths.ortho library and its du path operator/style but feel free to replace it with any solution you want. (The udlr/distance is measured between the border of the node and horizontal (middle) part of the path.)


\usepackage{tikz} \usetikzlibrary{paths.ortho}
  \node[inner sep=+0pt, outer sep=+0pt, anchor=base, name=#2, #1]{\m@th$#3$};}
  \tikz[baseline,remember picture]{\tnode@{#1}{#2}{#3}}\xdef\@tnodeclastnode{#2}}
  \tikz[baseline, remember picture]{
    \path[overlay] (#2) edge[TnodeC edge/.try,#4] coordinate (@tnodec@aux) (#5);
      \path (#2 |- @tnodec@aux) -- (#2);
\tikzset{TnodeC edge/.style={
  du, udlr/distance=2ex, shorten >=+4\pgflinewidth, shorten <=+4\pgflinewidth}}
Gummies cheesecake gingerbread. Jelly-o applicake cupcake. Marshmallow gingerbread jelly
 beans soufflé gingerbread. Sesame snaps apple pie chocolate bar chocolate gummies
  R^{\alpha\beta} - \frac{1}{2} R g^{\alpha\beta} + g^{\alpha\beta} \Lambda =
  \frac{8 \pi G}{c^4 \mu_0} 
    F^{\alpha\Tnode {a}{\scriptstyle\psi}}
    F_{     \TnodeC {b}{\scriptstyle\psi}[blue,stealth-stealth]}
    {}^{\beta} + \frac{1}{4} g^{\alpha \beta} F_{\psi\tau} F^{\psi\tau}
    F^{\Tnode  {@a}{\scriptstyle\psi}}
Caramels halvah apple pie cookie pastry wafer lollipop croissant jujubes. Tart cupcake
 pastry. Gingerbread candy sesame snaps pastry oat cake jelly beans. Soufflé chocolate
 gummi bears.

  \Tnode {aa}{\psi} \quad\TnodeC*{bb}{\pi} [out=30, in=150, looseness=10, <->]


enter image description here

  • 2
    Wot no tikzmark? – Loop Space Sep 14 '13 at 18:22
  • I see now that tikzmark has a \subnode macro, an \Rnode or \rnode equivalent. I'll try that also. Thanks. – Dominic Sep 14 '13 at 20:15
  • @Dominic Actually the \subnode macro wouldn't be of use here. The \subnode macro is intended to go inside a node of a larger TikZ picture. – Loop Space Oct 2 '13 at 8:45

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.