19

What is the best way to write something like 6.22E-21 in LaTeX, given that I don't want the numerals to be \tt, I do want the E to be small, and I may want the exponent to be negative (without the huge LaTeX minus sign)?

I'm sure this is a duplicate of another question that I just can't find.

Example here: enter image description here

U2EF1
  • 293
  • 1
  • 2
  • 6
  • 1
    The description is not letting me visualise what you want.(But, may be, I am the only one.) Perhaps, why not give us a sample to think about? – kan Sep 07 '12 at 02:59
  • @KannappanSampath I tried, it wouldn't let me post images. I've added a link. – U2EF1 Sep 07 '12 at 03:06
  • You could try $6.22\mbox{\textsc{e}}-21$. I'm assuming this number will be typeset on math mode, right? If you don't want a (typographically correct) math minus sign but a simple dash, be sure to include it in the argument of the \mbox command. – Mico Sep 07 '12 at 03:39
  • @Mico $6.22\mbox{\sc{e}-}21$ is definitely the correct answer, it looks exactly how I'd like it to! You should post that so I can checkmark it. – U2EF1 Sep 07 '12 at 05:22

4 Answers4

36

By far the most elegant way to do it is using the siunitx package:

\documentclass{article}
\usepackage{siunitx}
\sisetup{output-exponent-marker=\textsc{e}}
\begin{document}
\num{6.02e23}
\end{document}

calculator style

EDIT 1: If you want a short minus sign, a not so elegant solution (but still within siunitx) is to replace this more complicated sisetup line:

\sisetup{output-exponent-marker=\textsc{e}, bracket-negative-numbers, open-bracket={\text{-}}, close-bracket={}}

short minus

This will in general affect also negative numbers (even without exponents) used within \num. For other hacks regarding the minus sign look at this question Making a shorter minus or Typesetting of negative versus minus?, no answer on this was really satisfactory to me.

EDIT 2 (2014): If you make XeLaTeX use Écran Font (for example) and some TikZ shadows you can give it a complete look

calc

(note the use of the unicode chacaracter "ᴇ", I needed to use this particular font because it was the only one with this character)

\documentclass{article}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{fontspec}
\setmainfont[ExternalLocation={./}]{ecran-monochrome---monochrome-display.ttf} % Écran Monochrome
\usepackage{tikz}
\newcommand\calcshadow[1]{
\tikz[baseline]{
    \node[black!50!white] at (0.02,-0.02) {\num[output-exponent-marker=\text{ᴇ}, output-decimal-marker=\text{.}, bracket-negative-numbers, open-bracket={\text{-}}, close-bracket={}]{#1}};
    \node[] at (0.,0.) {\num[output-exponent-marker=\text{ᴇ}, output-decimal-marker=\text{.}, bracket-negative-numbers, open-bracket={\text{-}}, close-bracket={}]{#1}};
}
}
\begin{document}
\colorbox{gray!70}{
\calcshadow{6.02e-23}
}
\end{document}

EDIT 3: Alternative style using unicode block character "█":

blockcalc

...
\newcommand\calcshadow[1]{
\tikz[baseline]{
    \node[black!20!white] at (0.,0.) {████████};
    \node[black!80!white,opacity=0.5] at (0.02,-0.02) {\num[output-exponent-marker=\text{ᴇ}, output-decimal-marker=\text{.}, bracket-negative-numbers, open-bracket={\text{-}}, close-bracket={}]{#1}};
    \node[] at (0.,0.) {\num[output-exponent-marker=\text{ᴇ}, output-decimal-marker=\text{.}, bracket-negative-numbers, open-bracket={\text{-}}, close-bracket={}]{#1}};
}
}
...
alfC
  • 14,350
  • That looks good, how does it handle minus signs in the exponent? One problem (that I didn't put in my question): I'm using matplotlib, so extra packages probably aren't an option. – U2EF1 Sep 07 '12 at 05:23
  • @alfC You'll get a minus sign with siunitx: the question seems to be after what you see with a calculator, which is much more hyphen-like. – Joseph Wright Sep 07 '12 at 05:52
  • See my edit. If you can't load external packages then use another solution, like Fabio's or Mico's. – alfC Sep 07 '12 at 06:08
  • If you go into TikZ pgfmath already offers pretty printing options. – percusse Apr 05 '14 at 10:11
  • Another suggestion. Instead of the hyphen, you could make a rounded rule: exactly like a minus, but with the length and width you desire. I think it will look much better than that hyphen. – Manuel Apr 06 '14 at 21:21
  • @Manuel, thanks for the suggestion. I was looking for that before. However is that mathrule something standard or I need to incorporate all the code in the postings? If so, I prefer to hack/scale/raise math $-$ insteadm, such as ${}^-$, like described in my answer here: http://tex.stackexchange.com/a/152323/1871.

    These are other questions that can benefit from this: http://tex.stackexchange.com/questions/4756/typesetting-of-negative-versus-minus?lq=1 http://tex.stackexchange.com/questions/6058/making-a-shorter-minus?lq=1

    – alfC Apr 06 '14 at 21:31
  • You don't need to include it, my intention was just to point that out for future readers. However, yes, there are other questions that can benefit from that ;) – Manuel Apr 06 '14 at 21:40
11

For a one-off implementation of your typesetting needs, you could try

6.22\mbox{\sc{e}-}21

This will work in both text and math mode. If you use the amsmath package, you should type

6.22\text{\sc{e}-}21

as this is slightly more general than the first solution. Specifically, it'll work better if the expression ever occurs in scriptstyle (first-level sub- and superscripts) or scriptscriptstyle (second-level sub- and superscripts) material.

Conversely, if you have a lot of numbers that you wish to typeset in this way, you should implement a solution along the lines provided in @AlfC's answer. Otherwise, sooner or later some inconsistencies in the way you typeset these numbers will creep in.

Mico
  • 506,678
6

It is working in LaTeX, http://www.ctan.org/pkg/lcd .

enter image description here

For 10,

\DefineLCDchar{10}{00000000000000010111101011010110111}

For small caps shape {E},

\DefineLCDchar{12}{00000000000111101000011100100001111}

It may be necessary, http://latexcolor.com/

Thanks a lot, Mike Kaufmann.

Özgür
  • 3,270
3

You could try this code:

% this has to go in the preamble of the document.
\DeclareMathSymbol{\minus}{\mathord}{operators}{"2D} % unary minus
\newcommand{\scinot}[2]{#1\,\textrm{\scriptsize E}{#2}} % scientific notation
$\scinot{10}{\minus2}$
alfC
  • 14,350
Sylar
  • 306