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}
  • When you use \coordinate you are giving the same name (A) to all of them. It is not good. – Sigur Feb 26 '18 at 17:06
  • You miss a brace \begin{document – Sigur Feb 26 '18 at 17:07
  • I understand that. It works for now, so far, but surely i need to change that once. – Peanto Feb 26 '18 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 Feb 26 '18 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 Feb 26 '18 at 17:11
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}
  • 1
    It's also enough if you put curly braces around the comma. – bmv Feb 26 '18 at 17:13
  • That works, indeed. thank you very much for your help. – Peanto Feb 26 '18 at 17:13
  • @bmv I didn't know that. Thanks :) – Phelype Oleinik Feb 26 '18 at 17:14

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.