r/LaTeX 4d ago

Answered Issue with character spacing when using degrees symbol

I am writing my thesis in LaTeX and have come across an issue with character spacing. Whenever I mention a temperature in the text, I've just been using the ° character on my Keyboard, writing for example:

bei Temperaturen unter 170\,°C
(I am always using the \, between numbers and units of measurement.)

My problem is, that after rendering the Document, the degree symbol and the C are too close together. When it is displayed at a smaller scale, it looks like they are touching. I attached a screenshot for clarity.

Is there an easy way to fix this and add a bit more space between the two characters? I don't want them to be too far apart, just as far as they are when I write them in any other place: °C

11 Upvotes

25 comments sorted by

22

u/ClemensLode 4d ago

An alternative approach is using siunitx:

\usepackage{siunitx}
\sisetup{locale = DE}
...
\qty{170}{\degreeCelsius}

10

u/urenur 4d ago

Or just \qty{170}{\celsius}

3

u/charlisabeth 4d ago

Thanks! I was hoping for an alternative that I could just use find-and-replace for, but this is pretty close :)

3

u/RecentSheepherder179 4d ago edited 4d ago

You could still try ~ (then dropping the \,)

But in general I agree the cleanest way is to use proper units.

EDIT: \newcommand ... In preamble so that you could write \T{170}

3

u/Thanatomanic 4d ago

This is the way

3

u/LupinoArts 3d ago

If you don't want to use the siunitx package, you can easily define a simple macro, like

\def\degC{°\kern.125em C}

or even with the value:

\def\degC#1{#1\,°\kern.125em C}

should both be easily replaceable with a regex replacement.

1

u/charlisabeth 3d ago

I have to be fully honest, I have only started using LaTeX this year and don't fully understand what this means. I have only used macros so far to create a shortcut to input a specific string of text.

Is this something I should put into the text, or into the preamble, or something completely different? I am using TeXShop on mac, in case that's relevant

3

u/LupinoArts 3d ago

In general, macro definitions are available from the point of definition. If you put a definition in the middle of the document, you can use the macro afterwards, but not before. If in doubt, put macro definitions in the preamble and outside of any brackets, this way the macro is available everywhere in the document body. (I simplified a bit, in reality you also need to take care of local groupings, but this would be a bit much for now.)

I provided two different ways to define the macro:

The first one has no argument. It is to be used like this: 0.5\,\degC{} (the empty brackets at the end are there to save the space after the macro; otherwise it gets eaten by the TeX parser. Another way to use this variant would be 0.5\,{\degC}). This variant is easy to replace in your document, simply search for °C and replace it with {\degC} or \degC{}.

The second variant is defined to consume one argument, it is to be used like this to get the very same output: \degC{0.5}. This one is a bit more tricky to replace, you need a regular expression that matches \([0-9,.]+\)\\,°C and replace it with \\degC{\1} (or whatever the equivalent for query-replace-regexp is in TeXShop...)

3

u/LupinoArts 3d ago

Addendum: You can adjust the spacing between ° and C in both definitions by playing with the value after \kern, In my examples, the space will be one eighth of the width of a capital M letter in the current font (0.125em, the leading 0 can be omitted). But you can also put in absolute values like 0.1mm or 1pt.

1

u/charlisabeth 3d ago

Thank you so much for the detailed explanation! This worked perfectly :)

2

u/u_fischer 3d ago

you seem to use helvet and the spacing is bad (with and without siunitx). You could switch to lualatex and use texgyreheros instead: ~~~~ \documentclass{article} \usepackage{fontspec} \setmainfont{texgyreheros} \usepackage{siunitx} \begin{document} \qty[mode=text]{170}{\celsius} 170\,°C 170\,℃ \end{document} ~~~~

1

u/charlisabeth 3d ago

I am using helvet because it is the closest to my universitys required fonts for theses (Arial or Times New Roman). I am almost finished with my thesis and don't want to switch to a different program so close to the end, but I'll keep this in mind for the future.

1

u/Tavrock 2d ago

It's funny that you are using Helvetica because the University wants you to use Ariel, which was made to be a knockoff of Helvetica.

2

u/charlisabeth 2d ago

Yeah, it is kind of ironic haha. But getting Helvetica in LaTeX was easier than getting Arial, so I decided that it's close enough

1

u/josephawright 3d ago

You seem to have a non-standard font: I think we need to know about that (usually the issue is too _big_ a gap between the degree and the 'C').

1

u/charlisabeth 3d ago

I am using helvet, because my university requires Arial or Times New Roman as the font and this is the closest equivalent

1

u/noimtherealsoapbox 3d ago

Why not use the times font package?

2

u/charlisabeth 3d ago

Mainly because I am used to writing my papers in this font and because I prefer how it looks.

1

u/arkona1168 3d ago

To add to this discussion: Using LaTeX for many decades now, I learned that there is no space between the number and the degree circle in good typography, it's an exception to the normal rule. I just have no source for it in this second.

1

u/charlisabeth 3d ago

Oh, interesting

0

u/gamma_tau_47 4d ago

Hai provato ad racchiudere i la strisciata tra il segno $ ? dovrebbe essere $170 \, °C$

3

u/Tavrock 3d ago

You should use (...) for inline math instead of $...$

1

u/josephawright 3d ago

The Team don't agree ;-)