我可以在 tikz 中做這樣的事情,但是我該如何定義\wd
形狀寬度?
\makeatletter
\pgfdeclareshape{myshape}{%
\inheritsavedanchors[from=rectangle]%
\inheritanchorborder[from=rectangle]%
\inheritanchor[from=rectangle]{center}%
%
\backgroundpath{%
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa+0.5\wd}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
}%
}
\makeatother
答案1
嗯,這似乎可行:我可以將東北點的座標添加到西南點的負值上。
\newdimen{\pgf@dx}
\pgfextractx{\pgf@dx}{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\southwest}}}
答案2
官方獲取寬度的方法如下
\southwest% \pgf@xa=\pgf@x% \northeast% \advance\pgf@x by-\pgf@xa%
我打電話給這位官員是因為你可以在pgfmoduleshapes.code.tex
第 1036-1040 行看到它
要獲得北錨,最短路線是
\southwest% \pgf@xa=.5\pgf@x% \northeast% \advance\pgf@xa by.5\pgf@x%