myBOX
我已使用定义了一个名为 的自定义形状。我的目标是从点到\pgfdeclareshape
画一条线,并将其连接到节点 左侧线的中点。请找到我的(0,0)
(0,2)
myBOX
代码,输出和期望输出下面提供。
代码
\documentclass{article}
\usepackage{tikz}
\pgfdeclareshape{myBOX}{
\anchor{center}{\pgfpointorigin}
\savedanchor\PinA{\pgfpoint{0}{10}}
\anchor{PINA}{\PinA}
\foregroundpath{
\pgfpathrectanglecorners{\pgfpoint{0}{0}}{\pgfpoint{30}{20}}
\pgfusepath{draw}
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(2,0) node[myBOX, red] {};
\end{tikzpicture}
\end{document}
输出
期望输出
答案1
感谢 Paul A:
代码
\documentclass{article}
\usepackage{tikz}
\pgfdeclareshape{myBOX}{
\anchor{center}{\pgfpoint{0}{10}} %% <- Solution (Thanks to Paul A)
\savedanchor\PinA{\pgfpoint{0}{10}}
\anchor{PINA}{\PinA}
\foregroundpath{
\pgfpathrectanglecorners{\pgfpoint{0}{0}}{\pgfpoint{30}{20}}
\pgfusepath{draw}
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(2,0) node[myBOX, red] {};
\end{tikzpicture}
\end{document}
输出
答案2
为什么要使用\pgfdeclareshape
简单的矩形?
TikZ 风格还不够吗?
\documentclass{article}
\usepackage{tikz}
\tikzset{
myBOX/.style={
minimum width=30,
text height=15, text depth=5,
inner sep=0pt, draw,
anchor=west
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(2,0) node[myBOX, red] {};
\end{tikzpicture}
\end{document}