TikZ:在字体标志上放置箭头

TikZ:在字体标志上放置箭头

在此处输入图片描述

将这样的箭头放在字体符号上的最佳方法是什么?
如果我更改字体大小,这个示例就会在我耳边飞过。

如果我改变字体大小,我想要一致的箭头(注释),例如\tiny而不是 \Huge

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}

\begin{document}
\foreach\Fontsize in {\Huge, \small}{%%
\begin{tikzpicture}[
font=\sffamily\Fontsize,
>=stealth,
No/.style={font=\sffamily\tiny, near start,  inner sep=1pt},
]
\node[draw=lightgray, minimum size=2em](symbol){A};
%% Orientation: 
%\fill[red] (0,0) circle[radius=1pt];
%\draw[red] (120:1.0em) -- (0,0);

\draw[->, blue] (220:1.05em) -- +(0.3em,1em) node[No, left]{1};
%% .... How to put a node on a "to-path"?
\draw[->, blue, bend left] (120:1.0em)  to[bend left] (50:1.0em);
\path[blue] (120:1.0em) -- (0,0) node[No, above left]{2};
\end{tikzpicture}
}%%

答案1

这是一项建议,无论字体大小如何,箭头/数字都保持在同一位置。经过微小修改,它还可以适应实际字体大小,以保持字母符号周围的相同空间。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}

\tikzset{
    use bounding box relative coordinates/.style={
        shift={(current bounding box.south west)},
        x={(current bounding box.south east)},
        y={(current bounding box.north west)}
    },
}

\begin{document}

\foreach\Fontsize in {\Huge, \small}{%%
\begin{tikzpicture}[
font=\sffamily\Fontsize,
>=stealth,
No/.style={font=\sffamily\tiny,inner sep=1pt},
]
\draw[gray,use as bounding box] (0,0) rectangle (8ex,8ex);
\begin{scope}[use bounding box relative coordinates]
\node[] at (0.5,0.5) (symbol) {A};
\draw[->, blue] (0.1,0.1) --++ (70:0.5) node[near start,No, left]{1};
\path[draw,->,blue]
node[No,anchor=south] at (0.1,0.8) {2} 
(0.1,0.8) to[bend left] (0.9,0.8) 
;
\end{scope}
\end{tikzpicture}
}
\end{document}

在此处输入图片描述 在此处输入图片描述

附录:用于与原始发帖人进一步讨论

此代码会为每种字体大小生成一页,其中会进行缩放以使高度保持不变,无论实际字体大小如何。这是为了表明字符不会因字体大小不同而缩放,而是有所不同。

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{calc}
\usetikzlibrary{arrows.meta,bending}

\begin{document}

\foreach\Fontsize in {\tiny,\scriptsize,\footnotesize,\small,\normalsize,\large,\Large,\LARGE,\huge,\Huge}{%%
\begin{tikzpicture}[
    font=\sffamily\Fontsize,
    >=stealth,
    No/.style={font=\sffamily\tiny,inner sep=1pt},
    ]
\node[draw=gray] {\resizebox{!}{\heightof{\normalsize A}}{\Fontsize A}};
\end{tikzpicture}
}
\end{document}

在此处输入图片描述

编辑scale=tikzpicture和级别node之间进行一些调整后

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,bending}

\tikzset{
    use bounding box relative coordinates/.style={
        shift={(current bounding box.south west)},
        x={(current bounding box.south east)},
        y={(current bounding box.north west)}
    },
}

\begin{document}

\foreach\Fontsize in 
%{\normalsize}{%
{\tiny,\scriptsize,\footnotesize,\small,\normalsize,\large,\Large,\LARGE,\huge,\Huge}{%%
\pgfmathsetmacro{\scalefactor}{height("\Fontsize A")/height("\Huge A")}
\begin{tikzpicture}[
font=\sffamily\Fontsize,
>={Stealth[length=1ex*\scalefactor]},
No/.style={font=\sffamily\tiny,transform shape},
scale={\scalefactor},
transform shape
]
\node[inner sep=0pt,use as bounding box,scale={1/\scalefactor},transform shape] at (0,0) (symbol) {A};
\begin{scope}[use bounding box relative coordinates]
\draw[gray] (-0.5,-0.1) rectangle (1.5,1.6);
\draw[->,line width=\scalefactor*0.3pt, blue] (-0.1,0.1) --++ (70:0.5) node[near start,No, left]{1};
\path[draw,->,line width=\scalefactor*0.3pt,blue]
node[No,anchor=south] at (0.1,1.1) {2} 
(0.1,1.1) to[bend left] (0.9,1.1) 
;
\end{scope}
\end{tikzpicture}
}
\end{document}

在此处输入图片描述

答案2

通过测量符号大小,例如

\pgfmathsetlengthmacro\symbolwidth{0.5*width("\Symbol")}
\pgfmathsetlengthmacro\symbolheight{0.5*height("\Symbol")}

在此处输入图片描述

%\documentclass[a4paper]{article}
\documentclass[margin=5mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}


\begin{document}
\def\Font{\sffamily\Huge} 
%\def\Font{}
\def\Symbol{\Font A}

\pgfmathsetlengthmacro\symbolwidth{0.5*width("\Symbol")}
\pgfmathsetlengthmacro\symbolheight{0.5*height("\Symbol")}
\begin{tikzpicture}[x=\symbolwidth, y=\symbolheight, 
No/.style={-stealth, font=\sffamily\tiny, blue, inner sep=1pt, near start},
]
\node[]{\Symbol};
% Help:
\draw[red] (0,0) circle[radius=1pt];
\draw[red] (220:1.5) -- (0,0);
%\draw[] (0,0) -- (1,0);

% Arrows:
\draw[No] (220:1.5) -- +(0.3,1.2) node[No, left]{1};
\draw[No,
postaction={decorate,    decoration={markings,
mark=at position 0.1 with {\node[above]{2};}}}
] (120:1.3)  to[bend left] (50:1.3);
\end{tikzpicture}
\end{document}

相关内容