我计划绘制以下图形。
箭头是手工画的,应该是圆形的。
我想到的是以下 MWE。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit,positioning,hobby}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\node (one) at (0,0) {$68 \times 62$};
\node (two) at (5,0) {$6 \times 7$};
\node (three) at (7,0) {$8 \times 2$};
\draw [->,thick,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={|\footnotesize|{distance}{}}}}] (one) to [out=45,in=135] (two);
\draw [->,thick,postaction={decorate,decoration={raise=-1.5ex,text along path,text align=center,text={|\footnotesize|{text}{}}}}] (one) to [bend right=45] (three);
\end{tikzpicture}
\end{document}
我在绘制图中箭头时卡住了。我该如何绘制该图。你能提出一些建议吗?
答案1
您可以使用库width=()
函数calc
,inner xsep=0pt
将箭头精确地定位在左节点内的数字上方或下方。这是可行的,因为所有数字的宽度都相同,大致为 1ex。
(当然,更正确的应该是,例如,意思是:从节点的左上角开始,[xshift={width("$68 \times 6$")-width("$6$")/2}.one north west]
向右移动到$68 \times 6$
的宽度减去 的宽度的一半。)$6$
one
我稍微简化了你的代码并得出了以下结论:
\documentclass[border=1mm, tikz]{standalone}
\usetikzlibrary{calc, shapes.misc}
\begin{document}
\begin{tikzpicture}[digits/.style={inner xsep=0pt, inner ysep=2pt}]
\node[digits] (one) at (0,0) {$68 \times 62$};
\node[rounded rectangle, rounded rectangle right arc=none, draw] (two) at (3,0) {$6 \times 7$};
\node[rounded rectangle, rounded rectangle left arc=none, draw] (three) at (4.25,0) {$8 \times 2$};
\draw[thick] ([xshift={width("$6$")-1ex/2}]one.north west) to [bend left=45] node[above] (label above) {digits equal} ([xshift={width("$68 \times 6$")-1ex/2}]one.north west);
\draw[thick] ([xshift={width("$68$")-1ex/2}]one.south west) to [bend right=45] node[below] (label below) {sum of digits $= 10$} ([xshift={width("$68 \times 62$")-1ex/2}]one.south west);
\draw[->, thick, shorten >=2pt] (label above) to [bend left=45] node[above] {multiply} (two);
\draw[->, thick, shorten >=2pt] (label below) to [bend right=45] node[below] {multiply} (three);
\end{tikzpicture}
\end{document}