67

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?

  • 1
  • 2
    There is nothing wrong with The angle is $30^\circ$., and the output is the same as siunitx's. – AboAmmar Aug 4 '17 at 22:55
  • I imagined something like \degree. – Viesturs Aug 5 '17 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 Sep 29 '17 at 15:01
61

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

  • 2
    Would you still use \ang if the text was "The temperature is 30 deg C"? – Viesturs Aug 5 '17 at 12:23
  • 17
    @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 5 '17 at 12:59
  • 4
    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 2 '17 at 21:04
  • 2
    @lblb could you add an example with that as another answer, please? – K.-Michael Aye Sep 26 '17 at 20:25
  • @K.-Michael Aye: Done. – lblb Sep 29 '17 at 14:55
22

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

  • 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 7:42
  • 3
    @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 7:51
16

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$
5

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}.

3

You can use ° directly with

\usepackage{textcomp}

Example:

\documentclass{article}

\usepackage{textcomp}

\begin{document}    

I love 25 °C in my room

\end{document}

Compiled

  • 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 Mar 21 at 15:44
  • Ups, edited, good – Blaztix Mar 21 at 16:03
  • How to type on the keyboard the ° symbol? – Viesturs Mar 21 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 Mar 21 at 19:54
  • On a Mac you use command + control + space and just search for degree glyph. – Szymon Bęczkowski Jul 5 at 8:43
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.

  • 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 Dec 25 '18 at 22:40

protected by Mensch Sep 7 at 14:14

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.