TikZ 中节点的典型形式是围绕节点文本的圆圈。shapes 包提供了许多其他形式。我找不到的是节点下方的开口半圆(或椭圆)。对此有什么想法或提示吗?谢谢 Renger
答案1
这主要受到以下启发: 创建节点形状
然而,这里它只是朝一个方向。我相信可以改进它,让它更容易旋转。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\tikzset{arc style/.initial={}}
\pgfdeclareshape{half circle}{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{south}
\inheritanchor[from=circle]{west}
\inheritanchor[from=circle]{north}
\inheritanchor[from=circle]{east}
% can add more anchors if necessary
\inheritbackgroundpath[from=circle]
\beforebackgroundpath{
% get and set options
\pgfkeys{/tikz/arc style/.get=\tmp}
\expandafter\tikzset\expandafter{\tmp}
\tikz@options
% get radius length and center coordinates
\radius \pgf@xa=\pgf@x
\centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% draw arc
\advance\pgf@yb by \pgf@xa
\pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpatharc{90}{-90}{\pgf@xa}
% change the last line to the following line if you want the half circle rotated in the other direction
% \pgfpatharc{90}{270}{\pgf@xa}
\pgfusepath{draw}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[
half circle,
fill=red!10, % can fill the circle if needed
minimum width=2cm,
arc style={red,thick}
] (c) {my half circle};
\end{tikzpicture}
\end{document}