1

I am accustomed to using the degree symbol in LaTeX and know most of the ways to create it. However I am unable to use the degree symbol within a text decoration. In the following example I simply include the degree symbol as such to illustrate my question:

\path [decorate,decoration={text along path,raise=-2.4ex,text align={left indent=1.1cm},
text={|\sffamily\normalsize\color{MediumBlue}|D U S K~~~at latitude 31.5°N}}]
plot[smooth,tension=0.5] coordinates{   <list of coordinates>   };

(Apologies that this is not a proper MWE but just one tikz command with coordinates omitted.)

The error message is as follows. The source file and TeX file is in UTF-8 coding (according to Notepad++). I also include the \usepackage[utf8]{inputenc} statement.

enter image description here

UPDATE:

Here is the requested MWE...

\documentclass[a4paper,portrait]{minimal}
\usepackage{tikz}
\usetikzlibrary{spath3}
\usetikzlibrary{decorations.text}   % to print text on a curve
\begin{document}
\begin{tikzpicture}
\path[spath/save=test] plot[smooth,tension=0.5] coordinates{(0,1.1) (2,0.8) (4,1.0) (6,0.5) (8,0.7)};
\draw [spath/use=test];
\path [decorate,decoration={text along path,raise=-2.4ex,text align={left indent=1.1cm},
text={|\sffamily\normalsize\color{blue}|D U S K~~~at latitude 51.5°N}}]
plot[smooth,tension=0.5] coordinates{(0,1.1) (2,0.8) (4,1.0) (6,0.5) (8,0.7)};
\end{tikzpicture}
\end{document}

and thanks to Qrrbrbirlbel for providing the correct answer, which I will post below.

2
  • 1
    Please transform your code snippet into something we can copy and compile. Thank you.
    – MS-SPO
    Commented May 18, 2023 at 10:26
  • 2
    You'll need to use {°} or {\textdegree}. Commented May 18, 2023 at 11:22

1 Answer 1

2

Thanks to Qrrbrbirlbel whose comment is correct. The corrected MWE is:

\documentclass[a4paper,portrait]{minimal}
\usepackage{tikz}
\usetikzlibrary{spath3}
\usetikzlibrary{decorations.text}   % to print text on a curve
\begin{document}
\begin{tikzpicture}
\path[spath/save=test] plot[smooth,tension=0.5] coordinates{(0,1.1) (2,0.8) (4,1.0) (6,0.5) (8,0.7)};
\draw [spath/use=test];
\path [decorate,decoration={text along path,raise=-2.4ex,text align={left indent=1.1cm},
text={|\sffamily\normalsize\color{blue}|D U S K~~~at latitude 51.5{°}N}}]
plot[smooth,tension=0.5] coordinates{(0,1.1) (2,0.8) (4,1.0) (6,0.5) (8,0.7)};
\end{tikzpicture}
\end{document}

and the resulting PDF shows ...

enter image description here

Why am I hesitant about adding braces into text for decoration? Because the contents within braces are rotated as if they are just one character. To illustrate this just put the entire text within braces thus:

\path [decorate,decoration={text along path,raise=-2.4ex,text align={left indent=1.1cm},
text={|\sffamily\normalsize\color{blue}|{D U S K~~~at latitude 51.5{°}N}}}]
plot[smooth,tension=0.5] coordinates{(0,1.1) (2,0.8) (4,1.0) (6,0.5) (8,0.7)};

And this results in the following incorrect decoration:

enter image description here

So be aware of this side-effect. Rotating just one character is intentional, so both solutions from Qrrbrbirlbel provide the desired solution. Thanks again!

P.S.

It's worth mentioning that including the following line in your preamble and using {°} also works and gives you a larger degree symbol (or more accurately a raised circle):

\DeclareUnicodeCharacter{00B0}{\ensuremath{{}^\circ}}

This effect may be more pleasing/readable as a decoration:

enter image description here

You must log in to answer this question.

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