0

I am using tikzpicture the first time, trying to create a plot. As soon as I add a comma in the line which starts with %%%%%% (here just to highlighting purposes)between S_T and (,) K, latex cannot create a file. what's wrong? thanks in advance

\documentclass[a4paper, 10pt]{article}
\usepackage[parfill]{parskip}
\usepackage[german]{varioref}
\usepackage{url}
\usepackage{amsmath} 
\usepackage{dcolumn}
\setcounter{tocdepth}{4}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{intersections}
\begin{document

\begin{figure}[h] \centering
\begin{tikzpicture}
\draw[->] (0,0) -- (10,0);
\draw[->] (0,0) -- (0, 5);
\draw (2,0) -- (6,4);
\draw (4,0) -- (6,-4);
\draw (6,0) -- (10,4);
\draw[dashed] (4,0) -- (4,2);
\draw[dashed] (4,2) --(0,2);
\coordinate[label=left:$\text{Payoff}$] (A) at (0,3);
\coordinate[label=left:$S_T$] (A) at (10,-0.5);
\coordinate[label=center: $S_{\hat{\theta}-1}$] (K) at (2,-0.5);
\coordinate[label=left: $S_{\hat{\theta}}$] (A) at (4,-0.5);
\coordinate[label=center: $S_{\hat{\theta}+1}$] (A) at (6,-0.5);
\coordinate[label =center: $\delta$] (A) at (-0.5,2);
\coordinate[label =center: $C_T(S_T,KS_{\hat{\theta}-1})$] (A) at (4,4);
\coordinate[label =center: $C_T(S_TKS_{\hat{\theta}+1})$] (A) at (8,4);
%%%%%%\coordinate[label =center: $-2 \times C_T(S_T,KS_{\hat{\theta}})$] (A) at (7.5,-3);
\end{tikzpicture}
\end{figure}
5
  • When you use \coordinate you are giving the same name (A) to all of them. It is not good.
    – Sigur
    Commented Feb 26, 2018 at 17:06
  • You miss a brace \begin{document
    – Sigur
    Commented Feb 26, 2018 at 17:07
  • I understand that. It works for now, so far, but surely i need to change that once.
    – Peanto
    Commented Feb 26, 2018 at 17:08
  • lets summarize it quickly, my code works, except of the change of the last line, if i add a comma at the mentioned place.
    – Peanto
    Commented Feb 26, 2018 at 17:09
  • correct is \coordinate[label =center: {$-2 \times C_T(S_T,KS_{\hat{\theta}})$}] (A) at (7.5,-3);. observe added curly braces
    – Zarko
    Commented Feb 26, 2018 at 17:11

1 Answer 1

3

Apart from the missing } in \begin{document and the missing \end{document}...

TikZ treats commas as field delimiters, even if they are in math mode. So you have to hide them in a pair of {} to make it work:

\documentclass[a4paper, 10pt]{article}
\usepackage[parfill]{parskip}
\usepackage[german]{varioref}
\usepackage{url}
\usepackage{amsmath} 
\usepackage{dcolumn}
\setcounter{tocdepth}{4}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{intersections}
\begin{document}

\begin{figure}[h] \centering
\begin{tikzpicture}
\draw[->] (0,0) -- (10,0);
\draw[->] (0,0) -- (0, 5);
\draw (2,0) -- (6,4);
\draw (4,0) -- (6,-4);
\draw (6,0) -- (10,4);
\draw[dashed] (4,0) -- (4,2);
\draw[dashed] (4,2) --(0,2);
\coordinate[label=left:$\text{Payoff}$] (A) at (0,3);
\coordinate[label=left:$S_T$] (A) at (10,-0.5);
\coordinate[label=center: $S_{\hat{\theta}-1}$] (K) at (2,-0.5);
\coordinate[label=left: $S_{\hat{\theta}}$] (A) at (4,-0.5);
\coordinate[label=center: $S_{\hat{\theta}+1}$] (A) at (6,-0.5);
\coordinate[label =center: $\delta$] (A) at (-0.5,2);
\coordinate[label =center: {$C_T(S_T,KS_{\hat{\theta}-1})$}] (A) at (4,4);
\coordinate[label =center: $C_T(S_TKS_{\hat{\theta}+1})$] (A) at (8,4);
\coordinate[label =center: {$-2 \times C_T(S_T,KS_{\hat{\theta}})$}] (A) at (7.5,-3);
\end{tikzpicture}
\end{figure}
\end{document}
3
  • 1
    It's also enough if you put curly braces around the comma.
    – bmv
    Commented Feb 26, 2018 at 17:13
  • That works, indeed. thank you very much for your help.
    – Peanto
    Commented Feb 26, 2018 at 17:13
  • @bmv I didn't know that. Thanks :) Commented Feb 26, 2018 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .