我已经使用构建了一个自定义形状pdfdeclareshape
,并在下图中使用它
我想独立于文本旋转边框,以便理想情况下它最终看起来像图像中的这个问题。
研究了pgf
手册和如何在 Tikz 中独立旋转节点和文本(例如),我认为我应该使用shape border rotate
,但并非所有形状都默认支持它。
我的自定义形状的边框可以独立于其文本旋转吗?(如果我的自定义形状可以改进,请随时批评。)
% arara: pdflatex
\documentclass[tikz]{standalone}
\makeatletter
\pgfdeclareshape{petal}
{
\inheritsavedanchors[from=circle] % this is nearly a circle
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{base}
\backgroundpath{
% origin
\centerpoint%
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\pgfutil@tempdima=\radius%
\pgfpathmoveto{\pgfpointadd%
{\pgfqpoint{\pgf@xc}{\pgf@yc}}
{\pgfqpoint{-\pgfutil@tempdima}{0\pgfutil@tempdima}}}
\pgfpatharc{180}{0}{\pgfutil@tempdima}
\pgfpathcurveto{%
\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0.9\pgfutil@tempdima}{-.9\pgfutil@tempdima}}}
{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0.5\pgfutil@tempdima}{-.5\pgfutil@tempdima}}}
{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}}
\pgfpathcurveto{%
\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}}
{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-0.8\pgfutil@tempdima}{-.8\pgfutil@tempdima}}}
{\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-\pgfutil@tempdima}{0\pgfutil@tempdima}}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,...,5}
{
\pgfmathparse{90-(\i-1)*360/5}
\node[draw=black,anchor=base,rotate=-(\i-1)*360/5,petal,minimum width=1.5cm] at (\pgfmathresult:1.2cm) {\i};
}
\end{tikzpicture}
\end{document}
答案1
您可以使用shape border rotate
某些形状存在的 (或定义您自己的特殊petal rotate
键)。但是,当您定义新形状时,您必须自己完成所有工作。绘制形状边框很简单,但您可能希望/必须手动定义锚点以反映此键中的值(此处未完成):
\documentclass[tikz]{standalone}
\makeatletter
\pgfkeys{/pgf/shape border rotate/.initial=0}
\pgfdeclareshape{petal}
{
\inheritsavedanchors[from=circle] % this is nearly a circle
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{base}
\savedmacro\petalparameters{%
\pgfmathsetmacro\shapeborderrotate{\pgfkeysvalueof{/pgf/shape border rotate}}%
\addtosavedmacro\shapeborderrotate%
}
\backgroundpath{
% origin
\petalparameters%
{% Make sure transformations are inside group.
\pgftransformshift{\centerpoint}%
\pgftransformrotate{\shapeborderrotate}%
\pgfutil@tempdima=\radius%
\pgfpathmoveto{\pgfqpoint{\pgfutil@tempdima}{0pt}}%
\pgfpatharc{0}{180}{\pgfutil@tempdima}%
\pgfpathcurveto{\pgfqpoint{-\pgfutil@tempdima}{-.5\pgfutil@tempdima}}%
{\pgfqpoint{-.5\pgfutil@tempdima}{-.75\pgfutil@tempdima}}%
{\pgfqpoint{0pt}{-1.5\pgfutil@tempdima}}
\pgfpathcurveto{\pgfqpoint{0pt}{-.75\pgfutil@tempdima}}%
{\pgfqpoint{\pgfutil@tempdima}{-.75\pgfutil@tempdima}}%
{\pgfqpoint{\pgfutil@tempdima}{0pt}}%
}%
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,...,5}
{
\pgfmathparse{90-(\i-1)*360/5}
\node[draw=black,anchor=base,shape border rotate=-(\i-1)*360/5,petal,minimum width=1.5cm] at (\pgfmathresult:1.25cm) {\i};
}
\end{tikzpicture}
\end{document}
答案2
使用 PSTricks。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\psset{linejoin=1}
\SpecialCoor
\def\atom#1%
{
\psccurve(0,0)(.3,.5)(1,1)(1,1.5)(0,2)(-1,1.5)(-1,1)
\rput{*0}(0,1){#1}
}
\begin{document}
\begin{pspicture}[showgrid=false](-3,-3)(3,3)
\multido{\ia=90+-72,\ib=0+-72,\in=1+1}{5}{\rput(.5;\ia){\rput{\ib}(0,0){\atom{\in}}}}
\end{pspicture}
\end{document}