63

I've been using -16 in my LaTeX code to write negative numbers.

But the problem with that, is in many displays and LaTeX rendering kits, it displays the - sign as extremely long and separated from all the other mathematical symbols (e.g. the 16).

Since I knew that LaTeX is an extremely thorough, powerful and complex language, I thought there definitely must be a way to pass this slightly annoying problem.

I don't really want my users looking at a mile-long negative sign.

Is there a way?

Example: I don't want this - too wide and ugly.

Zerium
  • 12,559
  • 4
    You've added an image of exactly what I'd expect to see. I was thinking more of your input: that just looks like $-16$ to me. – Joseph Wright Oct 26 '12 at 07:16
  • 1
    Seems like it is related to http://tex.stackexchange.com/questions/6058/making-a-shorter-minus and http://tex.stackexchange.com/questions/4756/typesetting-of-negative-versus-minus

    to make it shorter I use \text{-}

    – jens_bo Oct 26 '12 at 07:52
  • 2
    @jenson_bo -- these examples are indeed related. but the important thing is that the hyphen (what you get with \text{-} is not equivalent to a minus sign. better would be an en-dash (\text{--}) since it has about the same thickness as a minus, but the vertical positioning is off. – barbara beeton Oct 26 '12 at 12:26
  • @barbara beeton --yes, I noticed the difference. In the answer I gave below I used \scalebox to get a shorter minus in math mode. – jens_bo Oct 26 '12 at 19:39
  • @jenson_bo -- the nonsymmetric scaling of the minus is a good solution. +1 but you might want to call it something other than \minus, and make it an "ordinary" character to guarantee that the spacing is dependable. – barbara beeton Oct 26 '12 at 19:46

8 Answers8

45

I am not a fan of typing numbers in the text in mathmode. It's fine if you use a complete font, but what if you decide to change the math font later? I prefer to use the textminus from the textcomp package. If your editor is unicode capable you can enter the proper minus symbol directly.

Edit: siunitx is able to handle numbers correctly as well.

Edit 2: To respond a bit more to the question asked, there is no typographical difference between a 'minus' and 'negative' sign. The difference is the kerning: With $-12$ the sign is close to the number, with $10-12$ the minus has appropriate kerning between the numbers. In short, there should be no need to resize the minus sign for negative numbers as a good font should have a minus sign so that its length blends in well with text.

\documentclass{scrartcl}

\usepackage{textcomp}
\usepackage{mathpazo}
\usepackage{eulervm}
\usepackage[utf8]{inputenc}

\DeclareUnicodeCharacter{2212}{\textminus}% requires a unicode capable editor

\usepackage{siunitx}
\sisetup{
   detect-mode,
   detect-family,
   detect-inline-family=math,
}

\begin{document}

\noindent
Number \textminus10 (textcomp minus)\\
Number −10 (unicode minus)\\% requires a unicode capable editor
Number -10 (normal text minus)\\
Number $-10$ (all math mode)\\    
\vspace{1ex}
\noindent
Number \num{-16} (siunitx textmode. No bug, my bad. Sorry Joseph)\\
Number $\num{-16}$ (siunitx mathmode)

\end{document}

enter image description here

egreg
  • 1,121,712
Jörg
  • 7,653
  • 2
    We don't have any context in the question, but in the main I'd expect negative numbers to be more 'mathematical' in usage than 'textual'. For example, something like a temperature is 'mathematical', whereas a section number is 'textual'. – Joseph Wright Oct 26 '12 at 10:45
  • @JosephWright Not sure I understand what you mean. Would you write something like today it is $-16$ degrees in a text? – Jörg Oct 26 '12 at 10:50
  • It would depend on the context. In something 'textual' (like a letter) I would write it out in words, but in something more 'mathematical' (like a paper for work) I would use $-16$ (or more likely siunitx in math mode). – Joseph Wright Oct 26 '12 at 10:54
  • @JosephWright Alright, but if you mix something like MinionPro and Euler that would look a little silly. Also, if you define lining numbers for math mode and OSF for text you mix the two in body text, which I think is typographically not correct. – Jörg Oct 26 '12 at 10:56
  • This is a nice compilation. Could you add the output of siunitx to your examples? I am curious how \num{-10} looks in comparison. Personally the textcomp minus looks just right. – Alexander Oct 26 '12 at 11:02
  • @Alexander done – Jörg Oct 26 '12 at 11:13
  • @JosephWright Could you have a look at my updated MWE. Is that a bug in siunitx? – Jörg Oct 26 '12 at 11:13
  • @Jörg Not a siunitx bug: you are not detecting mode, so the package will always use the mode pre-selected. 'Out of the box', numbers are always typeset by siunitx in math mode (\mathnormal). – Joseph Wright Oct 26 '12 at 11:14
  • @JosephWright Silly me, sorry. Changed the MWE accordingly. – Jörg Oct 26 '12 at 11:19
  • 1
    Thank you! This should be part of any LaTeX best practices compilation. – Alexander Oct 26 '12 at 12:49
  • @Jörg: Knuth already discussed this in his Typesetting Concrete Mathematics paper, a nice read. – خالد حسني Oct 26 '12 at 12:59
  • 2
    Negative numbers are definitely math. A number representing a year or referring to a page is text: those numbers are not used in their mathematical meaning (you don't add/multiply years or page numbers, they're just labels). – egreg Feb 18 '14 at 10:49
  • 1
    Most importantly, the minus - should be just the same as the plus + without the vertical stroke. And that's what most fonts do. – yo' Feb 18 '14 at 11:01
24

David's

Using a hyphen as in (3) is just horrible, it's all wrong.

got me thinking and I guess a nice alternative (if you don't like the default length) is to define the command \minus like that:

\documentclass{article}
\usepackage{graphicx}
\newcommand{\minus}{\scalebox{0.75}[1.0]{$-$}}

\begin{document}
  $\minus 16$

  $-16$
\end{document}

where 0.75 is the horizontal scaling of the box. enter image description here

jens_bo
  • 1,752
4

enter image description here

\documentclass{article}

\begin{document}

1: ${}-16$

2: $-16$

3: -$16$

4: $^{-}16$

5: $^{-}!16$

\end{document}

I think the normal usage is as in (2) with the normal length minus sign, If used in prefix position TeX does give it closer spacing than when it is used as a binary operator (compare with (1) ).

Using a hyphen as in (3) is just horrible, it's all wrong.

It may depend on national customs but here in the UK for educational use it's customary to distinguish the number -16 from 0 - 16 more clearly so that you can wrote 3 - -16 etc and distinguish the prefix version as part of the number from the infix operator. Using one of (4) or (5) according to taste might be suitable for that usage.

David Carlisle
  • 757,742
4

If you use the siunitx package, it cares about the right sign and font:

\documentclass[parskip]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{tgschola}

\usepackage{siunitx}
\sisetup{
   detect-family,
   detect-inline-family=math,
}

\begin{document}
Textmode: \num{-16}

Mathmode: $\num{-16}$

\sffamily
Textmode: \num{-16}

Mathmode: $\num{-16}$

\ttfamily
Textmode: \num{-16}

Mathmode: $\num{-16}$
\end{document}

example

Torbjørn T.
  • 206,688
Tobi
  • 56,353
3

Look at the following:

\documentclass{article}
\usepackage{times}

\begin{document}
\begin{tabular}{rrrr}
  -16&--16&-$16$&$-16$\\
  +16&+16&+$16$&$+16$
\end{tabular}
\end{document}

comparison of - and --

The hyphen - from the text font (here Times) does not match the +, but the -- does. On the other hand the minus and plus in math mode match one another. And also one may wish to have the minus and plus match in weight the digits. So either do everything in text mode (and use --) or everything in math mode (perhaps with some math font having shorter minus and plus signs if you can find that rarity...)

  • I think that -- only matches the width of + by chance here since -- produces an en-dash which is a different glyph than a minus sign (which should really have the same width as a plus sign in every font). – Jasper Habicht Dec 16 '23 at 11:46
2

A while ago I started to use:

\newcommand{\p}{\textup{\texttt{+}}} % small unary plus
\newcommand{\m}{\textup{\texttt{-}}} % small unary minus
2

In Unicode, you might use the minus character − (U+2212), rather than the hyphen-minus -. You might like the former better.

Davislor
  • 44,045
0

After seeing how all the other answers work, with packages and text and whatnot, it made me think about it and went back and tried the simplest most obvious thing, just put it as an exponent on a blank space, and it worked great. Hopefully this way will be helpful to others.

$\ ^-16$

$x = \ ^-16$

$y_2 \geq \ ^-(1 - x_2) $

Renders as

Negative sign in latex

  • 2
    Welcome to TeX.SE. // Sorry, but I haven't seen a minus sign typest like this ever since, not in my lifetime, not in any contemporary or old book. Though the length of the minus sign might be good, its position is not. I recommend deleting or modifying this answer. – MS-SPO Sep 06 '21 at 21:06
  • Funny, most of my math teachers made leading negative signs as a sort of prepended exponent. For what it's worth, why didn't you offer the same comment on David Carlisle's answer above? I noticed after the fact that he actually did suggest the same thing. – Willoughby Will Sep 07 '21 at 03:14