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.

5
  • 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
    Commented Oct 26, 2012 at 7:16
  • 1
    Seems like it is related to tex.stackexchange.com/questions/6058/making-a-shorter-minus and tex.stackexchange.com/questions/4756/… to make it shorter I use \text{-}
    – jens_bo
    Commented Oct 26, 2012 at 7: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. Commented Oct 26, 2012 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
    Commented Oct 26, 2012 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. Commented Oct 26, 2012 at 19:46

8 Answers 8

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

13
  • 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
    Commented Oct 26, 2012 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
    Commented Oct 26, 2012 at 10:50
  • 1
    Thank you! This should be part of any LaTeX best practices compilation.
    – Alexander
    Commented Oct 26, 2012 at 12:49
  • 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
    Commented Feb 18, 2014 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'
    Commented Feb 18, 2014 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

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

3
  • When I add \usepackage{eulervm} the first Textmode: \num{-16} is set in Euler.
    – Jörg
    Commented Oct 26, 2012 at 10:57
  • Not on my system. As far as I know the Euler fonts only use their digits with euler-digits option
    – Tobi
    Commented Oct 26, 2012 at 11:02
  • As Joseph pointed out above you need detect-mode then.
    – Jörg
    Commented Oct 26, 2012 at 11:20
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.

0
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...)

1
  • 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). Commented Dec 16, 2023 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.

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
  • 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
    Commented Sep 6, 2021 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. Commented Sep 7, 2021 at 3:14

You must log in to answer this question.

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