在某些位置重复 tikz 绘图

在某些位置重复 tikz 绘图

在下面的代码中,有没有办法在蓝线上重复蓝色和绿色的图形,而不重复它们的代码

    \documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{y}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (5,0) node [black, xshift=.3cm, yshift=0cm] {$X$};
\draw [thick,-latex](0,0) -- (0,4.) node [black, xshift=0cm, yshift=.3cm] {$Y$};
\draw [ultra thick, blue] (1.4,1.4) +(-150:1.2cm) -- +(30:4cm) node [blue, xshift=.2cm, yshift=0cm] {$E$};
\draw [ultra thick, red] (1.4,1.4) node [red, xshift=0cm, yshift=0cm] {\huge .} +(-90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash} -- +(90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash};
\draw [very thick, green, densely dashed]  (1.4,1.4) +(-90:1.4cm) -- +(90:0cm);
\draw [ultra thick, red] (2.46,2.02) node [red, xshift=0cm, yshift=0cm] {\huge .} +(-90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash} -- +(90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash};
\draw [very thick, green, densely dashed]  (2.46,2.02) +(-90:2.02cm) -- +(90:0cm);
\draw [ultra thick, blue] (2.46,0) +(-90:.15cm) node [blue, xshift=0cm, yshift=-.35cm] {$$} -- +(90:.15cm);
\draw [ultra thick, red] (3.46,2.6) node [red, xshift=0cm, yshift=0cm] {\huge .} +(-90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash} -- +(90:.84cm) node [red, xshift=0cm, yshift=-.035cm] {\LARGE \textendash};
\draw [very thick, green, densely dashed]  (3.46,2.6) +(-90:2.6cm) -- +(90:0cm);
\end{tikzpicture}
\vskip-2.3cm \hskip1.52cm
\begin{tikzpicture}[scale=.2, transform shape,rotate=-90]
\draw[red, very thick] (.1,.2) to [out=0,in=180, looseness=1.] +(0.:.2cm) to [out=0,in=180, looseness=.68] +(50:3.cm) to [out=0,in=180, looseness=.68] +(-50:3.cm) to [out=0,in=180, looseness=1.] +(0.:.2cm);
\draw [red, very thick] (2.23,2.5)-- (2.23,0);
\end{tikzpicture}
\vskip-1.488cm \hskip2.478cm
\begin{tikzpicture}[scale=.2, transform shape,rotate=-90]
\draw[red, very thick] (.1,.2) to [out=0,in=180, looseness=1.] +(0.:.2cm) to [out=0,in=180, looseness=.68] +(50:3.cm) to [out=0,in=180, looseness=.68] +(-50:3.cm) to [out=0,in=180, looseness=1.] +(0.:.2cm);
\draw [red, very thick] (2.23,2.5)-- (2.23,0);
\end{tikzpicture}
\vskip-1.45cm \hskip3.38cm
\begin{tikzpicture}[scale=.2, transform shape,rotate=-90]
\draw[red, very thick] (.1,.2) to [out=0,in=180, looseness=1.] +(0.:.2cm) to [out=0,in=180, looseness=.68] +(50:3.cm) to [out=0,in=180, looseness=.68] +(-50:3.cm) to [out=0,in=180, looseness=1.] +(0.:.2cm);
\draw [red, very thick] (2.23,2.5)-- (2.23,0);
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案1

充实 Ignasi 的评论:用于pic重复元素。

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\tikzset{my graph/.pic={
\draw[red, very thick] (-2.13,.2) to [out=0,in=180, looseness=1.] +(0.:.2cm) to [out=0,in=180, looseness=.68] +(50:3.cm) to [out=0,in=180, looseness=.68] +(-50:3.cm) to [out=0,in=180, looseness=1.] +(0.:.2cm);
\draw [red, very thick] (0,2.5)-- (0,0);
\draw [red, very thick,{Bar[]}-{Bar[]}] (-4,0) -- (4,0);
}
}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{y}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (5,0) node [black, xshift=.3cm, yshift=0cm] {$X$};
\draw [thick,-latex](0,0) -- (0,4.) node [black, xshift=0cm, yshift=.3cm] {$Y$};
\draw [ultra thick, blue] (1.4,1.4) +(-150:1.2cm) -- +(30:4cm) node [blue, xshift=.2cm, yshift=0cm] {$E$}
pic[pos=0.22,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.22] (x1)
pic[pos=0.46,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.46] (x2)
pic[pos=0.68,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.68] (x3)
;
\foreach \X in {1,2,3}
{
\draw [very thick, green, densely dashed]  (x\X) -- (x\X |-0,0);
}
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

附录:背景上的绿线。

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\tikzset{my graph/.pic={
\draw[red, very thick] (-2.13,.2) to [out=0,in=180, looseness=1.] +(0.:.2cm) to [out=0,in=180, looseness=.68] +(50:3.cm) to [out=0,in=180, looseness=.68] +(-50:3.cm) to [out=0,in=180, looseness=1.] +(0.:.2cm);
\draw [red, very thick] (0,2.5)-- (0,0);
\draw [red, very thick,{Bar[]}-{Bar[]}] (-4,0) -- (4,0);
}
}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{y}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (5,0) node [black, xshift=.3cm, yshift=0cm] {$X$};
\draw [thick,-latex](0,0) -- (0,4.) node [black, xshift=0cm, yshift=.3cm] {$Y$};
\draw [ultra thick, blue] (1.4,1.4) +(-150:1.2cm) -- +(30:4cm) node [blue, xshift=.2cm, yshift=0cm] {$E$}
pic[pos=0.22,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.22] (x1)
pic[pos=0.46,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.46] (x2)
pic[pos=0.68,rotate=-90,scale=0.2]{my graph} coordinate[pos=0.68] (x3)
;
\begin{scope}[on background layer]
\foreach \X in {1,2,3}
{
\draw [very thick, green, densely dashed]  (x\X) -- (x\X |-0,0);
}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容