답변에서 다음 코드를 사용하여이 질문
\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}
다음 수정 방법:
두 개의 사선이 아닌 하나의 사선만 그리도록 스타일 수정
지정된 위치와 사선(2007년과 2008년 사이의 지점)의 교차점에서 최종 지정된 위치(2006년)까지 빨간색 선을 그립니다.
답변1
hat
두 번째 요점을 해결하는 스타일은 다음과 같습니다 . 불행히도 첫 번째 요점은 이해가 되지 않습니다. "두 개가 아닌 하나의 사선만 그린다"는 것은 무엇을 의미합니까? 즉, 어느 두 선을 참조하고 있습니까?
\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}