Mit dem folgenden Code aus der Antwort aufdiese Frage
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.8, transform shape, -|/.style args={of #1 at #2}{insert path={(intersection cs:first line={#1}, second line={(#2,0)--(#2,10)}) coordinate (aux) (#2,0) |- (0,0|-aux) }}, vert/.style args={of #1 at #2}{insert path={(#2,0) -- (intersection cs:first line={#1}, second line={(#2,0)--(#2,10)}) }}]% this is used when drawing 2 lines to intersect with
\pgfmathsetmacro{\incrmnty}{1.}
\pgfmathsetmacro{\incrmntx}{2.}
\pgfmathsetmacro{\xlab}{2006}
\pgfmathsetmacro{\xn}{5}
\pgfmathsetmacro{\yn}{5}
\begin{scope}[xshift=0cm, yshift=0cm]
\draw [thick](0,0) -- (\incrmntx*\xn+\incrmntx*1,0);
\node at (\incrmntx*\xn+\incrmntx*1,\incrmnty*\yn-.4) (endx){};
\draw [thick](0,0) -- (0,\incrmnty*\yn);
\end{scope}
\begin{scope}[xshift=0cm, yshift=0cm]
\foreach \x [evaluate=\x as \aff using int(\xlab+(1*\x))] in {0,...,\xn}{\draw [black!40!white] (\incrmntx*\x+\incrmntx*.4,0) node [black, xshift=0cm, yshift=-.68cm, font=\footnotesize] {\aff} -- +(-90:.2);}
\end{scope}
\draw[blue!40!black, densely dashed, line width=.4mm] (-.1*\incrmntx,1.56*\incrmnty) node [black, left, yshift=-.06cm] {Intercept} -- (endx.center);
\draw[blue!80!white, thick, dashed, -|={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn+\incrmntx*.4}}] node [black, left, yshift=.06cm] {2011 value};
\draw[blue!80!white, thick, dashed, -|={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn-2+\incrmntx*.4}}] node [black, left, yshift=-.06cm] {2010 value};
\draw[blue!80!white, thick, dashed, vert={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn-4+\incrmntx*.4}}];
\draw[red!80!white, thick] (\incrmntx*\xn-7+\incrmntx*.4,2.58*\incrmnty) -- (\incrmntx*\xn-10+\incrmntx*.4,2.58*\incrmnty) node [black, xshift=.6cm, yshift=.3cm] {Slope} -- +(-90:.82cm);
\end{tikzpicture}
\end{frame}
\end{document}
So nehmen Sie die folgenden Änderungen vor:
Ändern des Stils, um nur eine schräge Linie statt zwei zu zeichnen
Zeichnen der roten Linie vom Schnittpunkt des angegebenen Standorts mit der schrägen Linie (ein Punkt zwischen 2007 und 2008) zum endgültigen angegebenen Standort (im Jahr 2006)
Antwort1
Hier ist ein Stil, hat
um den zweiten Punkt anzusprechen. Den ersten Punkt verstehe ich leider nicht. Was meinst du mit „nur eine schräge Linie zeichnen, statt zwei“, d. h. welche zwei Linien meinst du?
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.8, transform shape,
-|/.style args={of #1 at #2}{insert path={(intersection cs:first line={#1}, second line={(#2,0)--(#2,10)}) coordinate (aux) (#2,0) |- (0,0|-aux) }},
vert/.style args={of #1 at #2}{insert path={(#2,0) -- (intersection cs:first
line={#1}, second line={(#2,0)--(#2,10)}) }},
hat/.style args={of #1 at #2 and #3}{insert path={%
(intersection cs:first line={#1}, second line={(#2,0)--(#2,10)}) |-
(intersection cs:first line={#1}, second line={(#3,0)--(#3,10)})
}}
]% this is used when drawing 2 lines to intersect with
\pgfmathsetmacro{\incrmnty}{1.}
\pgfmathsetmacro{\incrmntx}{2.}
\pgfmathsetmacro{\xlab}{2006}
\pgfmathsetmacro{\xn}{5}
\pgfmathsetmacro{\yn}{5}
\begin{scope}[xshift=0cm, yshift=0cm]
\draw [thick](0,0) -- (\incrmntx*\xn+\incrmntx*1,0);
\node at (\incrmntx*\xn+\incrmntx*1,\incrmnty*\yn-.4) (endx){};
\draw [thick](0,0) -- (0,\incrmnty*\yn);
\end{scope}
\begin{scope}[xshift=0cm, yshift=0cm]
\foreach \x [evaluate=\x as \aff using int(\xlab+(1*\x))] in {0,...,\xn}{\draw [black!40!white] (\incrmntx*\x+\incrmntx*.4,0) node [black, xshift=0cm, yshift=-.68cm, font=\footnotesize] {\aff} -- +(-90:.2);}
\end{scope}
\draw[blue!40!black, densely dashed, line width=.4mm] (-.1*\incrmntx,1.56*\incrmnty) node [black, left, yshift=-.06cm] {Intercept} -- (endx.center);
\draw[blue!80!white, thick, dashed, -|={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn+\incrmntx*.4}}] node [black, left, yshift=.06cm] {2011 value};
\draw[blue!80!white, thick, dashed, -|={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn-2+\incrmntx*.4}}] node [black, left, yshift=-.06cm] {2010 value};
\draw[blue!80!white, thick, dashed, vert={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)} at {\incrmntx*\xn-4+\incrmntx*.4}}];
\draw[red!80!white, thick,hat={of {(-.1*\incrmntx,1.56*\incrmnty)--(endx.center)}
at {\incrmntx*\xn-10+\incrmntx*.4} and {\incrmntx*\xn-7+\incrmntx*.4}}]
node[black,pos=0.55,above right]{Slope};
\end{tikzpicture}
\end{frame}
\end{document}