3

Since I am a beginner with Tikz, I wanted to ask what is the best way to include labels to my lines, as in the picture: enter image description here

This is the code:

\usepackage{tikz}
\usetikzlibrary{calc} 
\usetikzlibrary{positioning,arrows.meta}

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
  extended line/.style={shorten >=-#1,shorten <=-#1},
  extended line/.default=1cm]

\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west] {\small state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east] {\small state 2};

\coordinate (A) at (0,0);
\coordinate (B) at (3,4);

\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M);                 
\draw [extended line=2.5cm, <->] ($(M)!0.5cm!270:(A)$) -- ($(M)!0.5cm!90:(A)$);

\node [dot=$x^{*}$] at (M) {}; 
\fill [red] (M) circle [radius=2pt] ; 


\end{tikzpicture}

\end{document}
Nenne
  • 697

1 Answers1

3

Just add something like node[pos=0.9,right]{Payoff space $X$} to the path.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc} 
% \usetikzlibrary{positioning,arrows.meta} % <-not used here

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
  extended line/.style={shorten >=-#1,shorten <=-#1},
  extended line/.default=1cm]

\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west,font=\small] {state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east,font=\small] {state 2};

\coordinate (A) at (0,0);
\coordinate (B) at (3,4);

\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M)
node[pos=0.9,right=1em]{Payoff space $X$};                 
\draw [extended line=2.5cm, <->] ($(M)!0.5cm!270:(A)$) -- ($(M)!0.5cm!90:(A)$)
node[pos=2.25,right=1em]{$m=x^*+\varepsilon$ space of discount factors};

\node [dot=right:$x^{*}$] at (M) {}; 
\fill [red] (M) circle [radius=2pt] ; 

\end{tikzpicture}

\end{document}

enter image description here

As for your additional question: here's a proposal. Please note that I dropped extended line from the second line since it makes things IHMO more complicated.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc} 
% \usetikzlibrary{positioning,arrows.meta} % <-not used here

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
  extended line/.style={shorten >=-#1,shorten <=-#1},
  extended line/.default=1cm]

\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west,font=\small] {state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east,font=\small] {state 2};

\coordinate (A) at (0,0);
\coordinate (B) at (3,4);

\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M)
node[pos=0.9,right=1em]{Payoff space $X$};                 
\draw [ <->] ($(M)!3cm!270:(A)$) -- ($(M)!3cm!90:(A)$)
node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors}
coordinate[pos=0.75] (x);
\draw[blue,-latex] (0,0) -- (x);
\node [dot=right:$x^{*}$] at (M) {}; 
\fill [red] (M) circle [radius=2pt] ; 

\end{tikzpicture}

\end{document}

enter image description here

  • Thank you a lot. How can I make the text smaller? – Nenne Apr 25 '19 at 15:49
  • @Nenne Just add e.g. font=\small, \draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M) node[pos=0.9,right=1em,font=\small]{Payoff space $X$}; \draw [extended line=2.5cm, <->] ($(M)!0.5cm!270:(A)$) -- ($(M)!0.5cm!90:(A)$) node[pos=2.25,right=1em,font=\small]{$m=x^*+\varepsilon$ space of discount factors}; –  Apr 25 '19 at 15:51
  • Thank you again. A further question, just to be sure of that: the package specifications such as \documentclass[...], \usepackage{tikz}, etc. should be set at the beginning of my whole document, or should be added whenever I start a new picture? – Nenne Apr 25 '19 at 15:54
  • @Nenne They need to go to the preamble, i.e. you cannot add them after \begin{document}. –  Apr 25 '19 at 15:58
  • To be a little more clear, I started my document with the preamble \documentclass[12pt,a4paper]{article}. Should I add also \documentclass[tikz,border=3.14mm]{standalone}? – Nenne Apr 25 '19 at 15:58
  • @Nenne That's fine, as long as you add \usepackage{tikz} \usetikzlibrary{calc} as you did it should work. Sebastiano was saying above that you should also add \documentclass[12pt,a4paper]{article} to your code. –  Apr 25 '19 at 16:00
  • Ok! If I wanted also to add a vector starting at (0,0) up to a given point of the space of discount factors, how could it be added in my code? – Nenne Apr 25 '19 at 16:04
  • 1
    @Nenne I added a proposal for that. –  Apr 25 '19 at 16:11
  • Ok, can I ask you how could I add a further vector starting at (0,0) up to another point of the space of discount factors? – Nenne Apr 29 '19 at 09:35
  • @Nenne Just add more points along the line, e.g. with coordinate[pos=0.4] (y) and draw the line. i.e. replace \draw [ <->] ($(M)!3cm!270:(A)$) -- ($(M)!3cm!90:(A)$) node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors} coordinate[pos=0.75] (x); by \draw [<->] ($(M)!3cm!270:(A)$) -- ($(M)!3cm!90:(A)$) node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors} coordinate[pos=0.75] (x) coordinate[pos=0.4] (y); \draw[blue,-latex] (0,0) -- (y);. –  Apr 29 '19 at 10:11
  • perfect!you helped me a lot! – Nenne Apr 29 '19 at 10:43
  • May I ask you also how could I tell TikZ to make the line of the payoff space dashed just from $x^{*}$ onwards? And how could I shorten the same line? Thank you again for your patience. – Nenne May 02 '19 at 11:43
  • 1
    @Nenne Replace \draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M) node[pos=0.9,right=1em]{Payoff space $X$}; by \path (A) -- (B) coordinate[midway] (M); \draw [shorten >=-0.5cm, ->] (M) -- (A); \draw [shorten >=-0.5cm, ->,dashed] (M) -- (B) node[pos=0.95,right=1em]{Payoff space $X$};, i.e. draw two separate lines. –  May 02 '19 at 11:47
  • Sorry, I wanted to do that on the perpendicular line. Can I use '\path' too? – Nenne May 02 '19 at 12:22
  • 1
    @Nenne For that replace \draw [ <->] ($(M)!3cm!270:(A)$) -- ($(M)!3cm!90:(A)$) node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors} coordinate[pos=0.75] (x); by \draw [->,dashed] (M) -- ($(M)!3cm!90:(A)$) node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors} coordinate[pos=0.5] (x); \draw [ ->] (M) --($(M)!3cm!270:(A)$) ; –  May 02 '19 at 15:00