105

In order to have the following output involving the degree symbol

enter image description here

I can try

\documentclass{report}
\begin{document}
The angle is 30$^\circ$.
\end{document}

However, this is an awkward manner to obtain the degree symbol - one reverts to math mode and casts an existing symbol into superscript.

Is there a straightforward way of obtaining the degree symbol?

Viesturs
  • 7,895

7 Answers7

97

I would use siunitx and so a semantic command:

\documentclass{report}
\usepackage{siunitx}
\begin{document}
The angle is \ang{30}.
\end{document}

enter image description here

But you can also load textcomp:

\documentclass{report}
\usepackage{siunitx}
\usepackage{textcomp}
\begin{document}
The angle is 
30\textdegree.
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • 2
    Would you still use \ang if the text was "The temperature is 30 deg C"? – Viesturs Aug 05 '17 at 12:23
  • 35
    @Viesturs: No. The meaning of \ang is angle, so I wouldn't misuse it for a temperature. I would use \SI{30}{\celsius}. – Ulrike Fischer Aug 05 '17 at 12:59
  • 5
    With your first example: I remember that siunitx uses the $^\circ$ crutch for its degree symbols (for compatibility reasons), which I find often doesn't look very fitting to the font in use (too thin lines, too large circle). So I tend to redefine the appropriate siunitx symbol commands for my needs, usually the appropriate unicode character. – lblb Sep 02 '17 at 21:04
  • This does not make it less awkward. See my explanation of WYSIWYM vs WYSIWYG. –  Jan 23 '19 at 02:01
  • 1
    @JonWong You seem to need only a simple 1-1 relation between input and output. My needs are more complicated. In accessible document I want to tag such units and add alternative text in the pdf, in a children math book I want to color them, in a tabular I want to print the radians instead of the degree. In Libreoffice you would apply styles and then change them, LaTeX uses (more powerful) macros. – Ulrike Fischer Jan 23 '19 at 08:29
  • @UlrikeFischer You should add something like This also works in math mode : $\alpha = \ang{30}$.. – projetmbc Oct 31 '22 at 17:44
36

The following example code serves to show that siunitx uses the ugly $^\circ$ construction as well (for compatibility reasons). Most fonts have a degree symbol for angles (U+00B0 DEGREE SIGN) and some have a degree Celsius symbol for temperatures (U+2103 DEGREE CELSIUS, output by \textcelsius in my example) and these symbols usually would fit better to the line widths of the font.

My example also shows that the single degree symbol and the one included in the special degree Celsius glyph do not have to be the same, so I personally would redefine it accordingly when I'm using both in a piece of work, see the second line.

Compile with XeLaTeX or LuaLaTeX.

\documentclass{article}
\usepackage{fontspec}
\usepackage{siunitx}

\begin{document}
°             % degree symbol
\si{\celsius} % ${}^{\circ}$
\textcelsius\ % special glyph of the font
\si{\degree}  % angle unit


\sisetup{
  math-celsius = °\text{C}, % for temperatures
  text-celsius = °C,
  math-degree = °, % for angles
  text-degree = °
}

°  
\si{\celsius} % now with the glyph
\textcelsius\ % special glyph of the font
\si{\degree}  % angle unit

\end{document}

screenshot

lblb
  • 3,454
  • 1
    I'm not sure how you measure 'most' fonts: classical TeX ones do not normally have a degree symbol. On degree Celsius, the single Unicode codepoint is a a compatibility character, and decomposes to 'degree' + 'letter C'. – Joseph Wright Sep 30 '17 at 07:42
  • 5
    @Joseph Wright: I wrote from experience of non-TeX fonts, that all of the ones I've come across have the ° (degree) symbol. With the degree Celsius, the second line in my example compares ° + C with the single glyph, and they look different (with the CM font, haven't tested other ones). These are just my conclusions, I'm not an expert on this. – lblb Sep 30 '17 at 07:51
32

There is also a gensymb package. I prefer it, since it provides just a symbol for both text/math modes, and you can do everything what you want with it.

Example:

\usepackage{gensymb}
% ...
$20 \degree$
ololobus
  • 420
11

The symbol is U+00B0 in Unicode, and the TS1 encoding contains it if you want to use legacy NFSS. The standard command for it is \textdegree and is defined by either textcomp or fontspec. You can also enter it in your UTF-8 source file, or use inputenc to declare a different input encoding. Virtually all text fonts support it.

Example:

\documentclass[varwidth]{standalone}
\usepackage{iftex}

\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage{textcomp} % For TS1.
  \usepackage[utf8]{inputenc} % The default since 2018.
\else
  \usepackage{fontspec}
\fi

\begin{document}
30\textdegree{} is hot.

20\textdegree{} is pleasing.

10\textdegree{} is not.

0\textdegree{} is freezing.
\end{document}

Sample image

There is also \textcelsius for the character ℃ (U+2103), but (as of the last time I checked) to get PDFLaTeX to recognize the UTF-8 character on input, you must add the command \DeclareUnicodeCharacter{"2103}{\textcelsius}.

Davislor
  • 44,045
7

You can use ° directly with

\usepackage{textcomp}

Example:

\documentclass{article}

\usepackage{textcomp}

\begin{document}    

I love 25 °C in my room

\end{document}

Compiled

Blaztix
  • 271
2

Using ^\circ is poor solution used in old days. Today, we have Unicode fonts. Almost all Unicode font supports the ° character. You can use it directly. For example in OpTeX:

\fontfam[lm]

I love 22,°C in my room.

{\bf I love 22,°C in my room.}

\bye

If you have complicated access to this character with your keyboard, you can define a macro for this. It is usual in TeX. For example

\fontfam[lm]
\def\deg{°}

I love 22,\deg C in my room.

{\bf I love 22,\deg C in my room.}

\bye

wipet
  • 74,238
0

I would suggest a fairly short and simple solution, without using additional and/or special packages for that purpose. In the preamble define the following: \renewcommand{\deg}{$^\circ$}

As \deg is a reserved word, it must be redefined for this purpose. In my usage, I have not yet seen any obstacle to do that.

Later, in the text, you can simply type The angle is 30\deg.

epR8GaYuh
  • 2,432
MSJ
  • 1
  • 5
    No, I don't think \deg (which is an function symbol) should be redefined for this. Your command will fail within math mode as well... The preferred way nowadays should be siunitx. Besides all, your proposition has been done by the O.P. already, apart from wrapping it up in a macro. –  Dec 25 '18 at 22:40
  • Generally \circ maps to U+2218 (Ring Operator), whereas the degree sign is U+00B0 (Degree Sign). In some fonts, using ^\circ can give a very small circle that is barely noticable, e.g. when using Fira Sans Math font. – Philipp Imhof May 21 '22 at 12:48