How to create an arrow from one number to another number (below a number list), similar to the picture below?
3 Answers
You can define TikZ nodes and use them later in a tikzpicture. You need to use the remember tag so that TikZ remembers your node after the local environment ends. In your tikzpicture you then need to use the overlay tag, so that the image can overlay other parts of your document.
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\newcommand{\mynode}[2]{%
\tikz[remember picture, baseline=(#1.base)]{%
\node(#1)[inner sep = 0, text = #2]{#1};%
}%
}
\begin{document}
$\mynode{130}{blue}, 131, 132, 133, \mynode{134}{red}, 135, 136, 137, 138, 139, 140$
\tikz[overlay,remember picture]
\draw[->, shorten <=.05cm, shorten >=.05cm]
(134)
|-
++(0,-0.5)
-|(130);
\end{document}
- 2,958
For TikZ is written the library tikzmark which is dedicated for such cases:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{lipsum}
\begin{document}
[
\tikzmarknode{A}{\color{blue}130}, 131, 132, 133, \tikzmarknode{B}{\color{red}134}, 135, 136, 137, 138, 139, 140
\tikz[overlay,remember picture]
\draw[->, shorten <=1pt, shorten >=1pt]
(B) -- ++(0,-0.5) -| (A);
\vspace{1ex} % for more vertical space for arrow
]
\lipsum[1][1-2]
\end{document}
- 296,517
A pstricks solution, using a simple array: just define the numbers to be connected as \rnodes and connect them with \pcbar.
\documentclass[svgnames]{article}
\usepackage{pst-node}
\begin{document}
\[ \setlength{\arraycolsep}{1pt}\begin{array}{*{11}{c}}
\rnode{A}{\color{blue}130}, & 131, & 132, & 133, & \rnode{B}{\color{red}134}, & 135, & 136, & 137, & 138, & 139, & 140
\end{array} \pcbar[linecolor =SteelBlue!80, arrowinset=0.12, arrows=->, angle=-90, nodesep=1.5ex](B)(A) \]%
\end{document}
- 271,350




\tikzmarkas in https://tex.stackexchange.com/questions/461217/using-tikzmark-and-arrows – Colo Oct 26 '20 at 16:32