TikZ - An arc with an arrow

Viewed 6702

I am learning Tikz and hope somebody can help me achieve the following i.e. I want to draw a directed arc between objects in an equation. Below is a picture of what I am trying to achieve. Arrow in TikZ

I have also attached the code I have used so far:

\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}

\begin{document}
\begin{tikzpicture}
    $(x+2)(x+3)$
\end{tikzpicture}
\end{document}

I also suspect that there is a way to specify a line or arc, between elements e.g. numbers and letters, without explicitly stating the coordinates. Is this the case? If it were, it would simplify the things I'm trying to achieve.

Any help would be very much appreciated.

2 Answers

The following solution draws an arc above the formula using arc; the actual angles and lengths may have to be adjusted. To get coordinates relative to the formula, the formula is wrapped into the node formula.

\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}

\begin{document}
\begin{tikzpicture}
    \node (formula) [] {$(x+2)(x+3)$};
    \draw[-latex,red] ($(formula.north west)+(.4,0)$) arc
    [
        start angle=160,
        end angle=20,
        x radius=0.5cm,
        y radius =0.5cm
    ] ;

\end{tikzpicture}
\end{document}

Output:

enter image description here

Another possibility with the tikzmark library:

\documentclass{article}
\usepackage{amsmath,amssymb,braket,tikz}
\usetikzlibrary{tikzmark,calc}

\begin{document}
\begin{equation}
    (\tikzmarknode{a}{x}+2)(\tikzmarknode{b}{x}+3)
\end{equation}
\tikz[remember picture, overlay]{\draw[-latex,red] ([yshift=0.1em]a.north) to[bend left] ([yshift=0.1em]b.north);}
\end{document}

enter image description here

Related