'tikz explain/annotate equation in LaTeX using straight arrows with right angles

Thanks to this excellent answer, I can get an equation as in this figure: with bent arrows. But what I really want is as in this figure: with right-angled arrows.

To simply write the code, you may start by modifying the code from here.



Solution 1:[1]

Update: I've turned equation annotation into a LaTeX annotate-equations package (also on CTAN), which you might find useful.


Adapting Mike Renfro's answer to straight edges is fairly straightforward: all I did was change from

\begin{tikzpicture}[overlay]
        \path[->]<1-> (nCPP) edge [bend left] (tCPP);
        \path[->]<2-> (nL) edge [bend left] (tL);
        \path[->]<3-> (nPPP) edge [out=0, in=0] (tPPP);
        \path[->]<4-> (nPP) edge [out=0, in=-90] (tPP);
\end{tikzpicture}

to

\begin{tikzpicture}[overlay,->]
        \draw<1-> (nCPP) -| (tCPP);
        \draw<2-> (nL) -| (tL);
        \draw<3-> (nPPP) -| (tPPP);
        \draw<4-> (nPP) -| (tPP);
\end{tikzpicture}

Changes explained:

  • replaced the edge and bend options with -| (there's also |- to bend at right angles the other way)
  • replaced \path with \draw to get the lines actually drawn
  • moved [->] into the tikzpicture environment options because for some reason it didn't work as \draw[->].

I've also set aspectratio=169 so there's enough space for the arrow for Predictor Prior Probability (it's also possible to work around that, but more hacky). This is what it looks like:

example annotation with straight edges

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1