我计划在数字上画一个箭头,如图所示:
到目前为止,我尝试过$\overset{\curvearrowleft}{5}$
,但它没有产生如图所示的箭头。我也试过这个:
\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}
此代码是整个文档的负担。它应该独立于 tikz 的任何其他节点/元素(没有mymatr-1-4.north
等)。
我需要一条线和一个简短的解决方案来绘制箭头,因为整个文档中有很多地方需要绘制箭头。这就是为什么我想让它简单、易于使用、内联且参数化(正如您在第二张图中所看到的,该数字可能包含多位数字)。
答案1
更新
\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}
旧答案
像这样?代码已注释
\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}