5

Is there a better way to put arrows between equations?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node at (-4,0) {$ (\underbrace{A_0})^2 -  \underbrace{\sigma_0^2}\, < K$};
\node at (-4,-1.5) {$= U_1 - L_2$};
\draw[thick, ->] (-5,-0.4) -- (-4.4,-1);
\draw[thick, ->] (-3.7,-0.4) -- (-3.5,-1);
\end{tikzpicture}
\end{document}

Equations have no meaning btw, just for demonstration.

Shin
  • 51

4 Answers4

5

Yet another approach, inspired by the tikzmark package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}

% see tikz documentation section III.17.13 "Referencing Nodes Outside the Current Picture"
\makeatletter
\newcommand{\tikzmarkMath}[2]{%
    \tikz[%
        remember picture, 
        baseline = (#1.base),
        inner sep = 0pt,
        outer sep = 0pt, % could be adapted instead of shorten
    ] \node (#1) {$\m@th\displaystyle #2$};%
}
\makeatother


\begin{document}

\begin{gather}
    % note the \vphantom to align the underbraces
    \big(\,\tikzmarkMath{A0}{\underbrace{A_0\vphantom{\sigma_0^2}}}\,\big)^2 
    - \tikzmarkMath{s0}{\underbrace{\sigma_0^2}}\rlap{\ensuremath{\, < K}} \\[2em]
    = \tikzmarkMath{U1}{U_1} 
    - \tikzmarkMath{L2}{L_2}
\end{gather}
%WARNING: do not forget the [overlay, remember picture]
\begin{tikzpicture}[overlay, remember picture, shorten >=5pt, shorten <=0pt]
\draw[thick, ->] (A0.south) -- (U1);
\draw[thick, ->] (s0.south) -- (L2);
\end{tikzpicture}

\end{document}

enter image description here

jakun
  • 5,981
4

A solution without tikz would be to use an array.

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
\[
\arraycolsep=2pt
\begin{array}{cccccc}
& \underbrace{(A_0)^2} & - & \underbrace{\sigma_0^2} & < & K\\
& \downarrow && \downarrow &&\\
= & U_1 & - & U_2 &&
\end{array}
\]
\end{document}

enter image description here

If you prefer the \downarrow arrows to be longer, there is information here.

Sandy G
  • 42,558
3

like this?

enter image description here

it is not clear what you think with a "better way". better code? nicer result? i try both (according to my taste, question is opinion base)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
    \begin{tikzpicture}
\matrix (m) [matrix of math nodes,
             row sep=11mm]
{
    & \underbrace{(A_0)^2} & - & \underbrace{\sigma_0^2} &  < K    \\
=   &            U_1       & - &      U_2                &         \\
};
\draw[thick, ->] (m-1-2) -- (m-2-2);
\draw[thick, ->] (m-1-4) -- (m-2-4);
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517
1

Reading comments from OP, it seems that OP wants the ability to number or label individual lines. In an array or matrix the rows aren't numbered/labeled, but in the align environment, getting the arrows and subsequent terms centered on the \underbrace is tricky. (Note that this leads to some unnatural spacing in the second line; it is my understanding that this is desired.)

Here is a solution that sets two lengths: \lena and \lenb, for the first and second underbraces respectively, then centers subsequent portions using \makebox and the prescribed widths.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{calc} % needed for \widthof command

\newlength{\lena}
\newlength{\lenb}

\begin{document}
\setlength{\lena}{\widthof{$\underbrace{(A_0)^2}$}}
\setlength{\lenb}{\widthof{$\underbrace{\sigma_0^2}$}}
\begin{align}
&\mathrel{\phantom{=}}{\underbrace{(A_0)^2}}-\underbrace{\sigma_0^2}<K\label{thisone}\\
&\mathrel{\phantom{=}}\makebox[\lena]{$\downarrow$}\mathbin{\phantom{-}}\makebox[\lenb]{$\downarrow$}\nonumber\\
&=\makebox[\lena]{$U_1$}-\makebox[\lenb]{$U_2$}\label{thatone}
\end{align}
Lines \ref{thisone} and \ref{thatone} can be referenced.
\end{document}

enter image description here

As mentioned in another answer, info on longer downarrows is here.

Sandy G
  • 42,558