我想要定义一个新的“T”形(即下图中的红色和绿色形状),以便我可以使用 TikZ 绘制下图。
不幸的是我不知道该怎么做。说实话,我读过 PGF 手册中的“声明新形状”一节,但我对低级 pgf 命令完全一头雾水。
我该怎么办?欢迎就任何方向提出建议。
答案1
最后,我成功地通过改编网络上现有的示例创建了一个“T”形。以下是定义该形状的 pgf 代码。
\makeatletter
\pgfdeclareshape{t}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{south east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{north west}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathparse{(\pgf@xb-\pgf@xa)/2}
\pgf@xc=\pgf@xa
\advance\pgf@xc by \pgfmathresult pt
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@ya}}
}
}
\makeatother