2

I am planning to draw an arrow over the digits like in the figures:

enter image description here enter image description here

So far I tried $\overset{\curvearrowleft}{5}$, but It didn't produce arrows as the figures. I also tried this:

\usepackage{tikz}
\usetikzlibrary{arrows.meta, matrix}
\begin{tikzpicture}
    \matrix[
    matrix of math nodes,
    nodes in empty cells,
    row sep=4pt,
    column sep=4pt,
    ] (mymatr) {
    1& 0 &1 &0 &1 &0 &1& 0& 1\\
    &+&1& 0& 1&0& 1& 0& 1\\
    1& 0 &1 &0& 1& 0& 1& 0& 1\\
    };
    \draw ([yshift=-2pt]mymatr-2-1.south west) -- ([yshift=-2pt]mymatr-2-9.south east);
    \draw[-Latex] (mymatr-1-4.north)  to[in=90, out=90, looseness=2]  node[midway, above, font=\footnotesize]{$1$} (mymatr-1-3.north);
\end{tikzpicture}

This code is burden for whole document. It should be independent of any other nodes/elements of tikz (without mymatr-1-4.north etc.).

I need a single line and short solution to draw the arrow as I have lots of places where the arrows will be drawn in the whole document. That's why I want make it simple, easy to use, inline and also parametric (as you see in the second figure, the number may contain multiple digits).

1

1 Answer 1

2

Update

screenshoot

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,matrix,arrows.meta,bending}
\begin{document}
   
%definition of arrow (fleche in fernch) 
\newcommand{\fleche}[3]{
\draw[-{Latex[flex]}] (#1.north) .. controls ++(0,.25) and ++(0,.25) .. node[midway, above, font=\footnotesize]{$#3$} (#2.north);
}

\begin{tikzpicture}
    \matrix[
    matrix of math nodes,
    nodes in empty cells,
    row sep=4pt,
    column sep=4pt,
    ] (mymatr) {
    1& 0 &1 &0 &1 &0 &1& 0& 1\\
    &+&1& 0& 1&0& 1& 0& 1\\
    1& 0 &1 &0& 1& 0& 1& 0& 1\\
    };
    \draw ([yshift=-2pt]mymatr-2-1.south west) -- ([yshift=-2pt]mymatr-2-9.south east);
    %------
    % arrows 
    \fleche{mymatr-1-4}{mymatr-1-3}{$1$}
    \fleche{mymatr-1-5}{mymatr-1-6}{$2$}
\end{tikzpicture}
\end{document}

Old answer

Like this? the code is commented

screenshoot

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows.meta,bending}%<- add bending library
\begin{document}


\begin{tikzpicture}
    \matrix[
    matrix of math nodes,
    nodes in empty cells,
    row sep=4pt,
    column sep=4pt,
    ] (mymatr) {
    1& 0 &1 &0 &1 &0 &1& 0& 1\\
    &+&1& 0& 1&0& 1& 0& 1\\
    1& 0 &1 &0& 1& 0& 1& 0& 1\\
    };
    \draw ([yshift=-2pt]mymatr-2-1.south west) -- ([yshift=-2pt]mymatr-2-9.south east);
    %-------------
    % add flex option, in= 60, out=120, looseness=1
    \draw[-{Latex[flex]}] (mymatr-1-4.north)  to[in=60, out=120, looseness=1,]  node[midway, above, font=\footnotesize]{$1$} (mymatr-1-3.north);
\end{tikzpicture}
\end{document}
11
  • I want something more shorter the the code provided. In-line code.
    – mmr
    Commented Nov 21, 2021 at 15:47
  • It should independent of any other nodes/elements of tikz (without mymatr-1-4.north etc.).
    – mmr
    Commented Nov 21, 2021 at 16:03
  • You want a macro ?
    – AndréC
    Commented Nov 21, 2021 at 16:24
  • 1
    I have updated my answer. Are you ok with macro \fleche?
    – AndréC
    Commented Nov 21, 2021 at 17:41
  • 1
    Ok, I will edit my answer tonight or tomorrow with the explanations because I have to go out walking my dog...
    – AndréC
    Commented Nov 21, 2021 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .