我需要使用哪些包来运行 \pgfdeclareshape 和 \pgf@xa、\pgf@xb、pgf@xc?

我需要使用哪些包来运行 \pgfdeclareshape 和 \pgf@xa、\pgf@xb、pgf@xc?

我一直试图使用 TikZ 和 PGF 手册(版本 3.1.3)第 1126 页中的以下示例,但当我这样做时,我得到了多个错误。特别是,编译器似乎无法识别名称 \pgf@xa、\pgf@xb 和 \pgf@xc。它还指出 @ 不应该位于 \advance 之后。我尝试了各种 \usepackage{} 语句,但没有成功。我不清楚 \pgfdeclareshape 应该在文档范围内还是在文档之前。

\pgfdeclareshape{document}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
% ... and possibly more
\backgroundpath{% this is new
% 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
% compute corner of ‘‘flipped page’’
\pgf@xc=\pgf@xb \advance\pgf@xc by-5pt % this should be a parameter
\pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% add little corner
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}\hskip-1.2cm
\begin{tikzpicture}
\node[shade,draw,shape=document,inner sep=2ex] (x) {Remark};
\node[fill=yellow!80!black,draw,ellipse,double]
at ([shift=(-80:3cm)]x) (y) {Use Case};
\draw[dashed] (x) -- (y);
\end{tikzpicture}

答案1

欢迎使用 TeX-SE!在 LaTeX 中,@它扮演着特殊角色,除非您在包中,或者您使用,否则它是一个非标准字符\makeatletter。这是为了保护某些宏、维度等不被意外覆盖。因此,您可能希望将形状的声明包装在中\makeatletter ... \makeatother,后者会切换回正常状态。在您的示例中,您还需要shapes.geometric椭圆。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\makeatletter
\pgfdeclareshape{document}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
% ... and possibly more
\backgroundpath{% this is new
% 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
% compute corner of ''flipped page''
\pgf@xc=\pgf@xb \advance\pgf@xc by-5pt % this should be a parameter
\pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% add little corner
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}
\makeatother
\begin{tikzpicture}
\node[shade,draw,shape=document,inner sep=2ex] (x) {Remark};
\node[fill=yellow!80!black,draw,ellipse,double]
at ([shift=(-80:3cm)]x) (y) {Use Case};
\draw[dashed] (x) -- (y);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容