0

I would like to present arithmetic progression by showing the terms of the progression and drawing an arrow from cell to cell to show this.

I managed to reach almost exactly what I want, but the arrows go from number to number, while I would like them to be slightly below (going from cell to cell).

Here is my current code :

\documentclass[10pt,a4paper]{book}
\usepackage{tikz}

\begin{document}

\newcommand{\insertph}[1]{%
 \tikz[remember picture] \node[inner sep=0pt,minimum height=10pt](#1){};} 
$$
{
\centering
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
        \hline
         $u_1$ & $u_2$ & $u_3$ & $u_4$ & \ldots & $u_n$ & $u_{n+1}$ & \ldots\\
        \hline
         $2\insertph{n1}$ & $\insertph{n2}4\insertph{n3}$ & $\insertph{n4}6\insertph{n5}$ & $\insertph{n6}8$ &  \ldots &  $u_n$\insertph{n7} & $\insertph{n8}u_{n+1}$  & \ldots \\ 
        \hline
    \end{tabular}\par
}
$$

\tikz[remember picture,overlay]\draw[->,blue] (n1.south) to  [out=-45,in=-150] node[below]{+2} (n2.south) ; 
\tikz[remember picture,overlay]\draw[->,blue] (n3.south) to[out=-45,in=-150] node[below]{+2}  (n4.south); 
\tikz[remember picture,overlay]\draw[->,blue] (n5.south) to[out=-45,in=-150] node[below]{+2} (n6.south); 
\tikz[remember picture,overlay]\draw[->,blue] (n7.south) to[out=-45,in=-150] node[below]{+2} (n8.south); 

\end{document}
 

And it yields the following result :

Result of my code

How could I make these little arrows drop by a few pixels ? A manual adjustment would be OK, even if I would prefer a slightly more versalite solution where I could just say "Make the arrow point from the bottom of a given column in my table to another column"

3

1 Answer 1

2

With nicematrix (and TikZ):

enter image description here

\documentclass{article}
\usepackage{nicematrix,tikz}
\tikzset{myarrow/.style={->, blue, thick, shorten <=2pt, shorten >=2pt}}

\begin{document}

\[
\pi =
\begin{NiceArray}{cccccccc}[hvlines]    
u_1 & u_2 & u_3 & u_4 & \cdots & u_n & u_{n+1} & \cdots\\
2 & 4 & 6 & 8 & \cdots & u_n & u_{n+1} & \cdots
\CodeAfter
     \begin{tikzpicture}
     \draw [myarrow] (3-|1.5) to [bend right] node[below] {$+2$} (3-|2.5);
     \draw [myarrow] (3-|2.5) to [bend right] node[below] {$+2$} (3-|3.5);
     \draw [myarrow] (3-|3.5) to [bend right] node[below] {$+2$} (3-|4.5);
     \draw [myarrow] (3-|6.5) to [bend right] node[below] {$+2$} (3-|7.5);
     \end{tikzpicture}
\end{NiceArray}
\]

\end{document}

With just TikZ:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{myarrow/.style={->, blue, thick, shorten <=2pt, shorten >=2pt}}

\begin{document}

\[
\pi=\begin{tikzpicture}[baseline]
\matrix(addtwo)[matrix of math nodes, nodes={anchor=center, draw, minimum height=4ex, minimum width=2em}, column sep=-\pgflinewidth, row sep=-\pgflinewidth]{
u_1 & u_2 & u_3 & u_4 & \cdots & u_n & u_{n+1} & \cdots\\
2 & 4 & 6 & 8 & \cdots & u_n & u_{n+1} & \cdots\\
};
\draw [myarrow] (addtwo-2-1.south) to [bend right] node[below] {$+2$} (addtwo-2-2.south);
\draw [myarrow] (addtwo-2-2.south) to [bend right] node[below] {$+2$} (addtwo-2-3.south);
\draw [myarrow] (addtwo-2-3.south) to [bend right] node[below] {$+2$} (addtwo-2-4.south);
\draw [myarrow] (addtwo-2-6.south) to [bend right] node[below] {$+2$} (addtwo-2-7.south);
\end{tikzpicture}
\]

\end{document}

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.