4

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}
  • 1
    You can use pos option, or near end, very near end, etc. – JouleV Apr 25 at 15:42
  • Missing \documentclass[...]{...} into your MWE. – Sebastiano Apr 25 at 15:43
4

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 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}; – marmot Apr 25 at 15:51
  • 1
    @Nenne I added a proposal for that. – marmot Apr 25 at 16:11
  • 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. – marmot May 2 at 11:47
  • 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)$) ; – marmot May 2 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.