2

Following my question here about how to plot a text along a path another question came up. How can I add math or commands with \command to the text along the path?

This here works:

postaction={decorate,decoration={text along path,text={|\scriptsize| Loading}}}

These do not:

postaction={decorate,decoration={text along path,text={|\scriptsize| 0\textdegree Loading}}}

postaction={decorate,decoration={text along path,text={|\scriptsize| 0$^{\circ}$ Loading}}}

I tried capsulating the commands and math with braces but this doesn't work either. No error is produced, just the compilation with pdflatex takes forever and doesn't end.

Can someone tell me why this does not work and how to fix that?

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\usepackage{textcomp}

\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    domain=0:2,
    xmin=0, xmax=2.25,
    ymin=0, ymax=4.5,
    samples=100,
    axis y line=center,
    axis x line=middle,
]
\addplot+[mark=none,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)};
\addplot[draw=none,
      postaction={decorate,decoration={text along path,
          text={|\scriptsize| Loading},raise=1ex,
          text align={center}
      }},
      domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot+[mark=none,black,domain=0.5:1.5,->,,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot[draw=none,postaction={decorate,decoration={text along path,
          text={|\scriptsize| Unloading},raise=-2ex,
          text align={center},
      }},
      domain=0.5:1.5] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
    \addplot+[<-,mark=none, black,domain=0.5:1.5,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}
1

Since it is a unit, I would use siunitx :

\addplot[draw=none,
      postaction={decorate,decoration={text along path,
          text={|\scriptsize| {\SI{0}{\degree}} Loading},raise=1ex,
          text align={center}
      }},
      domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};

Full code will be:

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}
\usepackage{textcomp}

\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    domain=0:2,
    xmin=0, xmax=2.25,
    ymin=0, ymax=4.5,
    samples=100,
    axis y line=center,
    axis x line=middle,
]
\addplot+[mark=none,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)};
\addplot[draw=none,
      postaction={decorate,decoration={text along path,
          text={|\scriptsize| {\SI{0}{\degree}} Loading},raise=1ex,
          text align={center}
      }},
      domain=0.5:1.5,] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot+[mark=none,black,domain=0.5:1.5,->,,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\addplot[draw=none,postaction={decorate,decoration={text along path,
          text={|\scriptsize| {\SI{0}{\degree}} Unloading},raise=-2ex,
          text align={center},
      }},
      domain=0.5:1.5] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
    \addplot+[<-,mark=none, black,domain=0.5:1.5,samples=150] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}

Note that we have to hide the \SI{0}{\degree} from tikz parser by using braces.

enter image description here

  • Thx once again @Harish Kumar – raedma Oct 23 '15 at 8:33
0

Thanks a lot @jarauth the link helped me to find the trick. I must have somehow missed that during my tests with brackets.

This here works like a charm:

postaction={decorate,decoration={text along path,text={|\scriptsize| 0{\textdegree} Loading}}}

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.