# Tikzpicture: Add slope angles to straight line

I am trying to add some angles between the x-axis and the red and blue line which indicate their slope.

\documentclass[15pt,a4paper,headinclude, totoc]{scrartcl}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
\pgfplotsset{ticks=none}
\begin{axis}[axis lines=middle,xmin=-0.2,xmax=4.5,ymin=-0.5,ymax=15, ultra thick,
xlabel=$\scriptstyle C_t$,
ylabel=$\scriptstyle C_{t+1}$,
x label style={at={(axis description cs:1,-0.01)},anchor=north},
y label style={at={(axis description cs:-0.15,1)},anchor=west},
]

\addplot+[no marks,gray,domain=1.2:4,samples=200, thick] {(13.06666)/(0.8*x-0.4) -0.83333} node[right]{\footnotesize $U^0$};
\addplot+[no marks,gray,domain=0.8:4,samples=200, thick] {(5.4)/(0.8*x-0.4) -0.83333 } node[right]{\footnotesize $U^1$};

\fill (1.8,11.73094) circle (2pt) node[right]{\tiny \textbf{A}};
\draw[gray, dash pattern=on 6pt off 3pt] (1.8,0) -- (1.8,11.73094);
\draw[gray, dash pattern=on 6pt off 3pt] (0,011.73094) -- (1.8,11.73094);

\fill[black] (1.8533,4.15433) circle (2pt) node[right]{\tiny \textbf{B}};
\fill (1.3357,7.2435) circle (2pt) node[right]{\tiny \textbf{C}};

\end{axis}
\end{tikzpicture}
\end{center}
\end{document}


Here you see my result so far. I need to adjust the labeling of the slopes. Thank you

• If you are using PGF/TikZ version 3 there is an angles library that does that (see manual) – Bordaigorl Jan 17 '16 at 17:14
• Instead \begin{center} .... \end{center} rather wrote \begin{document} ... \end{document} and add to your code snipped all used packages as well document class that it will be compilable. – Zarko Jan 17 '16 at 17:17
• @Zarko, I use several packages. I will add some of them to the code. – Mac Jan 17 '16 at 17:18

Try

    \documentclass[15pt,a4paper,headinclude, totoc]{scrartcl}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{angles,calc,intersections,quotes,positioning,shapes}

\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5,
my angle/.style args = {#1/#2}{draw,<->,
angle eccentricity=#2,
} % angle label position!
]
\pgfplotsset{ticks=none}
\begin{axis}[axis lines=middle,xmin=-0.2,xmax=4.5,ymin=-0.5,ymax=15, ultra thick,
xlabel=$\scriptstyle C_t$,
ylabel=$\scriptstyle C_{t+1}$,
x label style={at={(1,-0.01)},anchor=north},
y label style={at={(-0.15,1)},anchor=west},
no marks,
samples=100
]
\coordinate (O) at (0,0);
\coordinate (a1) at (0,29.12722);
\coordinate (a2) at (3.0138,0);
\pic [my angle=12mm/1.2, "$\alpha$",blue] {angle = a1--a2--O};
\coordinate (b1) at (0,20.15286);
\coordinate (b2) at (2.08522,0);
\pic [my angle=19mm/1.15, "$\beta$",red] {angle = b1--b2--O};

\addplot+[gray,domain=1.2:4,thick] {(13.06666)/(0.8*x-0.4) -0.83333} node[right]{\footnotesize $U^0$};
\addplot+[gray,domain=0.8:4,thick] {(5.4)/(0.8*x-0.4) -0.83333 } node[right]{\footnotesize $U^1$};

\fill (1.8,11.73094) circle (2pt) node[right]{\tiny \textbf{A}};
\draw[gray, dash pattern=on 6pt off 3pt] (1.8,0) -- (1.8,11.73094);
\draw[gray, dash pattern=on 6pt off 3pt] (0,011.73094) -- (1.8,11.73094);

\fill[black] (1.8533,4.15433) circle (2pt) node[right]{\tiny \textbf{B}};
\fill (1.3357,7.2435) circle (2pt) node[right]{\tiny \textbf{C}};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}


Above MWE gives:

Some explanation: For drawing angles I use tikz library angles (as suggest Bordaigorl in his comment. For it I determine coordinates, where red and blue lines intersect coordinate axes. Angles as such are drawn with\pic [my angle=12mm/1.2, "$\alpha$",blue] {angle = a1--a2--O};. For labels of angles is used library quotes".

Edit: With pgfplots v1.12 for coordinates is not necessary to use axis description cs: anymore. Since, all lines have the same number of samples and parameter no marks, both can be moved in axis preamble. With this MWE become more concise.

• Red instead of green line^^ but I try to adjust this. My label has to be a little bit bigger, i.e. "-(1+r')" and "-(1+r)" – Mac Jan 17 '16 at 17:55
• I observe, that I use data for green line instead for red one. Now I correct this mismatch (what is not big deal) and on the same time make some refinement of code. – Zarko Jan 17 '16 at 18:04
• I Zarko, thx for the guidance. Is there sth. special about "quotes"? The library doesn't work for me. I don't manage to get labels here. But maybe I just use some nodes for this. – Mac Jan 24 '16 at 8:25
• The quotes syntax is explained in TikZ manual, page 242; and their use with library angles` ion page 511. It should work, the figure is in answer is generated with posted code in answer. Possible cause of your problem (if my MWE doesn't work as it is), that you haven't installed recent version of TikZ (version 3.0.1a), from where I took page numbers in manual. – Zarko Jan 24 '16 at 8:36
• Ok thx for advice. I have a subsequent question regarding the diagram. May I use your modified code to post a new question? Thanks – Mac Jan 24 '16 at 8:41