我使用以下代码绘制多个 tikzpictures,共享相同的节点定义规范。
我怎样才能使这些节点定义规范成为全局的,而不是为每个 tikzpicture 重复它们(可能改变(.1,.2)的起始点的位置)
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (8,0);
\draw [thick,-latex](0,0) -- (0,3.);
\node [red] at (.1,.2) (begin){}
([shift={(-90.:1cm)}]begin.center) node (beginclip){}
([shift={(0.:.2cm)}]begin.center) node (beginr){}
([shift={(30:4.cm)}]beginr.center) node (midtop){}
([shift={(-30:4.cm)}]midtop.center) node (end){}
([shift={(0.:.2cm)}]end.center) node (endr){}
([shift={(-90.:1cm)}]endr.center) node (endrclip){}
([shift={(0:.5cm)}]beginr.center) node (arrowl){}
([shift={(180:.5cm)}]end.center) node (arrowr){}
;
\draw[blue, very thick] (begin.center) to [out=0,in=180, looseness=1.] (beginr.center) to [out=0,in=180, looseness=.68] (midtop.center) to [out=0,in=180, looseness=.68] (end.center) to [out=0,in=180, looseness=1.] (endr.center);
\path[clip] (beginclip.center) -- (begin.center) to [out=0,in=180, looseness=1.] (beginr.center) to [out=0,in=180, looseness=.68] (midtop.center) to [out=0,in=180, looseness=.68] (end.center) to [out=0,in=180, looseness=1.] (endr.center) -- (endrclip.center) -- cycle;
\pgfmathsetmacro{\DeltaX}{1.6}
\draw[blue, very thick] (3.76-\DeltaX,1.8) -- (3.76-\DeltaX,0) (3.76+\DeltaX,1.8) -- (3.76+\DeltaX,0);
\draw [blue, very thick] (3.76-\DeltaX,0.1) -- (3.76-\DeltaX,-0.1) node [blue, xshift=0cm, yshift=-.24cm] {-3.182}
(3.76+\DeltaX,0.1) -- (3.76+\DeltaX,-0.1) node [blue, xshift=0cm, yshift=-.24cm] {3.182};
\draw [ultra thick, blue] (midtop.center) node [blue, fill=blue!8, xshift=0cm, yshift=-1.2cm] {accept Ho} (midtop.center|-0,0) node [blue, xshift=0cm, yshift=0cm] {X};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
您可以将这些东西保存在 中pic
,它也接受参数。当然,您可以选择更多、更少和/或不同的参数。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{pics/.cd,
Hany/.style n args={3}{code={\draw [thick,-latex](0,0) -- (0,3.);
\node [red] at (.1,.2) (begin){}
([shift={(-90.:1cm)}]begin.center) node (beginclip){}
([shift={(0.:.2cm)}]begin.center) node (beginr){}
([shift={(30:4.cm)}]beginr.center) node (midtop){}
([shift={(-30:4.cm)}]midtop.center) node (end){}
([shift={(0.:.2cm)}]end.center) node (endr){}
([shift={(-90.:1cm)}]endr.center) node (endrclip){}
([shift={(0:.5cm)}]beginr.center) node (arrowl){}
([shift={(180:.5cm)}]end.center) node (arrowr){}
;
\draw[blue, very thick] (begin.center) to [out=0,in=180, looseness=1.] (beginr.center) to [out=0,in=180, looseness=.68] (midtop.center) to [out=0,in=180, looseness=.68] (end.center) to [out=0,in=180, looseness=1.] (endr.center);
\path[clip] (beginclip.center) -- (begin.center) to [out=0,in=180, looseness=1.] (beginr.center) to [out=0,in=180, looseness=.68] (midtop.center) to [out=0,in=180, looseness=.68] (end.center) to [out=0,in=180, looseness=1.] (endr.center) -- (endrclip.center) -- cycle;
\draw[blue, very thick] (3.76-#1,1.8) -- (3.76-#1,0) (3.76+#1,1.8) -- (3.76+#1,0);
\draw [blue, very thick] (3.76-#1,0.1) -- (3.76-#1,-0.1) node [blue, xshift=0cm, yshift=-.24cm] {-3.182}
(3.76+#1,0.1) -- (3.76+#1,-0.1) node [blue, xshift=0cm, yshift=-.24cm] {3.182};
\draw [ultra thick, blue] (midtop.center) node [blue, fill=blue!8, xshift=0cm,
yshift=-1.2cm] {#2} (midtop.center|-0,0) node [blue, xshift=0cm, yshift=0cm] {#3};
}}}
\begin{document}
\begin{frame}[t]
\frametitle{Parameters \texttt{{1.6},{accept Ho},{X}}}
\begin{tikzpicture}[scale=.9, transform shape]
\pic at (-3,0) {Hany={1.6}{accept Ho}{X}};
\end{tikzpicture}
\end{frame}
\begin{frame}[t]
\frametitle{Parameters \texttt{{1.4},{accept He},{Y}}}
\begin{tikzpicture}[scale=.9, transform shape]
\pic at (-3,0) {Hany={1.4}{accept He}{Y}};
\end{tikzpicture}
\end{frame}
\end{document}