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

4
  • 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 7, 2012 at 2:59
  • @KannappanSampath I tried, it wouldn't let me post images. I've added a link.
    – U2EF1
    Sep 7, 2012 at 3: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 7, 2012 at 3: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 7, 2012 at 5:22

4 Answers 4

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.

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}};
}
}
...
7
  • 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 7, 2012 at 5: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 7, 2012 at 5:52
  • See my edit. If you can't load external packages then use another solution, like Fabio's or Mico's.
    – alfC
    Sep 7, 2012 at 6:08
  • If you go into TikZ pgfmath already offers pretty printing options.
    – percusse
    Apr 5, 2014 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 6, 2014 at 21:21
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.

1
  • Well it has been a while, but that is pretty spiffy :)
    – U2EF1
    Aug 31, 2014 at 7:41
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}$

You must log in to answer this question.

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