107

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?

4
  • 1
    Have a look at How to insert degree Celsius symbol in node text in pgfplots/tikz?
    – dexteritas
    Commented Aug 4, 2017 at 22:18
  • 2
    There is nothing wrong with The angle is $30^\circ$., and the output is the same as siunitx's.
    – AboAmmar
    Commented Aug 4, 2017 at 22:55
  • I imagined something like \degree.
    – Viesturs
    Commented Aug 5, 2017 at 12:24
  • @AboAmmar: See my answer, siunitx does that for compatibility reasons. So if one strives for better looks then redefining them is best.
    – lblb
    Commented Sep 29, 2017 at 15:01

7 Answers 7

99

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

6
  • 2
    Would you still use \ang if the text was "The temperature is 30 deg C"?
    – Viesturs
    Commented Aug 5, 2017 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}. Commented Aug 5, 2017 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
    Commented Sep 2, 2017 at 21:04
  • 1
    This does not make it less awkward. See my explanation of WYSIWYM vs WYSIWYG.
    – user152148
    Commented Jan 23, 2019 at 2: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. Commented Jan 23, 2019 at 8:29
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

2
  • 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
    Commented Sep 30, 2017 at 7: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
    Commented Sep 30, 2017 at 7:51
33

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$
1
  • 2
    I love this simple and practical answer! Commented Apr 23, 2020 at 16:07
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}.

1
  • In current versions of LaTeX, it is no longer necessary to load textcomp.
    – Davislor
    Commented Aug 2, 2022 at 19:01
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

5
  • 4
    Actually textcomp is enough. Since 2018 utf8 is the predefined input encoding, and you'll find \DeclareUnicodeCharacter{00B0}{\textdegree} in utf8enc.dfu. AFAIK nowadays there is basically no use for gensymb.
    – campa
    Commented Mar 21, 2019 at 15:44
  • Ups, edited, good
    – Blaztix
    Commented Mar 21, 2019 at 16:03
  • How to type on the keyboard the ° symbol?
    – Viesturs
    Commented Mar 21, 2019 at 19:08
  • depends on the layout of your keyboard, you can insert by Alt+ 248, if you have USA International keyboard SHIFT + CTRL + ALT + ; | Best in Latam Keyboard SHIFT + `
    – Blaztix
    Commented Mar 21, 2019 at 19:54
  • On a Mac you use command + control + space and just search for degree glyph. Commented Jul 5, 2019 at 8:43
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
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.

2
  • 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.
    – user31729
    Commented Dec 25, 2018 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. Commented May 21, 2022 at 12:48

You must log in to answer this question.

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