5

I failed to add the red curved arrows to a tabular using TikZ. I feel ashamed... :-)

I am not looking for an automated solution.

enter image description here

Here is the code just for the table.

\documentclass[a4paper, 13pt]{scrartcl}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\usepackage{nicematrix}

\begin{document} \begin{NiceTabular}{r|l} $k$ & $u(k)$ \ \hline $0$ & $10$ \ \hline $1$ & $8,!5 = 0,!5 \times 10 + 3,!5$ \ \hline $2$ & $7,!75 = 0,!5 \times 8,!5 + 3,!5$ \ \hline $3$ & $7,!375 = 0,!5 \times 7,!75 + 3,!5$ \ \hline $4$ & $7,!1875 = 0,!5 \times 10 + 3,!5$ % Not good even with a straight arrow ! % \CodeAfter % \begin{tikzpicture} % \draw[->, red] (2-2) edge (3-2); % \draw[->, red] (3-2) edge (4-2); % \end{tikzpicture} \end{NiceTabular} \end{document}

projetmbc
  • 13,315

2 Answers2

5

Adaptations

  • use foreach loop for automation (creating the same arrow for all lines)
  • added a command basiceval for simple index calculation within the foreach loop
  • set option create-large-nodes for NiceTabular (see manual, section: "The 'medium nodes' and the 'large nodes'")
  • use the .east of the node and xshift and yshift for fine positioning
  • changed class option 13pt to fontsize=13pt to solve warning

Note

  • Instead of using ,\! to remove the space after the comma in math mode you could also use {,} or as global solution \usepackage{icomma} (but then you have to add a space after a comma if you want it).

Code

\documentclass[a4paper, fontsize=13pt]{scrartcl}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\usepackage{nicematrix}

\usepackage{tikz}

\def\basiceval#1{\the\numexpr#1\relax}

\begin{document} \begin{NiceTabular}[create-large-nodes]{r|l} $k$ & $u(k)$ \ \hline $0$ & $10$ \ \hline $1$ & $8,!5 = 0,!5 \times 10 + 3,!5$ \ \hline $2$ & $7,!75 = 0,!5 \times 8,!5 + 3,!5$ \ \hline $3$ & $7,!375 = 0,!5 \times 7,!75 + 3,!5$ \ \hline $4$ & $7,!1875 = 0,!5 \times 10 + 3,!5$

    \CodeAfter
    \begin{tikzpicture}
        \foreach \i in {2, ..., 5} {
            \draw[->, red] ([xshift=2mm, yshift=-.5mm] \i-2-large.east) to [bend left=50] ([xshift=2mm, yshift=.5mm] \basiceval{\i+1}-2-large.east);
        }
   \end{tikzpicture}
\end{NiceTabular}

\end{document}

Result

enter image description here

dexteritas
  • 9,161
  • Thanks a lot. The missing concept for me was the create-large-nodes feature. – projetmbc Oct 28 '21 at 15:57
  • Even if create-large-nodes is a perfect solution, you have other ways to access to the right end of your cells in nicematrix. See my answer below. – SebGlav Oct 29 '21 at 13:31
5

Just to leave another possibity (since the previous answer is already accepted), know that nicematrix creates nodes where the lines intersect in your table and at the centres of the cells, and you can access them easily:

\documentclass[a4paper, 12pt]{scrartcl}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{tikz}

\usepackage{nicematrix}

\begin{document} \begin{NiceTabular}{r|l}[name=A] $k$ & $u(k)$ \ \hline $0$ & $10$ \ \hline $1$ & $8,!5 = 0,!5 \times 10 + 3,!5$ \ \hline $2$ & $7,!75 = 0,!5 \times 8,!5 + 3,!5$ \ \hline $3$ & $7,!375 = 0,!5 \times 7,!75 + 3,!5$ \ \hline $4$ & $7,!1875 = 0,!5 \times 10 + 3,!5$

        \CodeAfter
        \begin{tikzpicture}
            \foreach \i in {1.5,2.5,...,5.5} 
                {
                \pgfmathsetmacro{\j}{\i+1};
                \draw[red,->] ([yshift=-2pt]\i-|3) to[out=-20,in=20,looseness=2] ([yshift=2pt]\j-|3);
                }
        \end{tikzpicture}
    \end{NiceTabular}

\end{document}

This method prevents you from using large nodes which is a good method too, by the way.

nicetabular and arrows

SebGlav
  • 19,186