6

How do we do this in LaTeX? The main problem is having two rows of values as upper indices.

enter image description here

azetina
  • 28,884
user11206
  • 319

5 Answers5

6

Sometimes the low-level commands are just nicer in my opinion:

\documentclass{article}
\begin{document}
\[ \mathrm{shaft = 20^{+0.080\atop +0.005} mm} \]
\end{document}

enter image description here

If you use amsmath, it will nag but does compile. However, it has been said it's better to use the higher-level macros with LaTeX, and so borrowing from Gonzalo's answer from a previous question, one might use something like the following with amsmath:

\documentclass{article}
\usepackage{amsmath}
\newcommand\scriptstack[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
%\genfrac{<left-delim>}{<right-delim>}{<thickness>}{<mathstyle>}{<numerator>}{<denominator>}
\begin{document}
\[
  \mathrm{shaft = 20^{\scriptstack{+0.080}{+0.005}} mm}
\]
\end{document}
morbusg
  • 25,490
  • 4
  • 81
  • 162
5

Without any package:

MWE

\documentclass{article}
\begin{document}
$\mathrm{shaft}=20^{\begin{array}{@{}c@{}}
\scriptscriptstyle +0.080\\[-7pt]
\scriptscriptstyle +0.005
\end{array}}\mathrm{mm}$
\end{document}
Fran
  • 80,769
4

Try

\documentclass[12pt,preview,border=3mm]{standalone}
\usepackage{amsmath}
%---------------------------------------------------------------%
        \begin{document}
\[\text{shaft} = 20^{\substack{+0.080\\+0.005}}\,\text{mm}\]
        \end{document}

But this is not standard notation for tolerance. For it see siunitx package. Edit: As mentioned Mico, third line arise substack for one line and \scriptscriptstyle make indices smaller: enter image description here Corrected code:

\documentclass[12pt,preview,border=3mm]{standalone}
\usepackage{amsmath}
%---------------------------------------------------------------%
        \begin{document}
\[\text{shaft} = 20^{\substack{\scriptscriptstyle+0.080\\\scriptscriptstyle+0.005\\~}}\,\text{mm}\]
        \end{document}
Zarko
  • 296,517
  • I think you may have to add \scriptscriptstyle in front of each element in the substack to make the numbers sufficiently small. Adding a third, empty, row may also be needed to raise the entire substack a bit more. – Mico Aug 28 '14 at 04:42
  • @Zarko Your solution is good but I prefer the other one – user11206 Aug 28 '14 at 08:52
4

Another solution using low level functions:

\documentclass{article}
\usepackage{amsmath,siunitx,xparse}

\NewDocumentCommand{\mySI}{O{}mom}{%
  \IfNoValueTF{#3}
   {\SI[#1]{#2}{#4}}
   {\SI[parse-numbers=false,#1]{\num[parse-numbers=true]{#2}\douncert{#3}}{#4}}%
}

\NewDocumentCommand{\douncert}{m}{%
  ^{%
   \vbox{
     \def\myrow##1{\num{##1}}
     \let\\=\cr\tiny
     \offinterlineskip\lineskip=1pt
     \halign{\myrow{##}\hfil\cr#1\crcr}
   }%
  }%
}

\NewDocumentCommand{\tvar}{m}{\textnormal{#1}}

\begin{document}
\[
\tvar{shaft}=\mySI{20}[+0.080\\+0.005]{mm}
\]
\end{document}

enter image description here

If you use \vcenter instead of \vbox, the result would be

enter image description here

egreg
  • 1,121,712
2

If you want something that produces the same vertical spacing as the O.P.'s example, you can try the stackengine package:

\documentclass[12pt,preview,border=3mm]{standalone}
\usepackage{amsmath}
\usepackage{stackengine}
\setstackEOL{\\}

\begin{document}

\[\text{shaft} = 20^{\,\setstackgap{L}{2ex}\everymath{\scriptscriptstyle}\Vectorstack{+0.080\\+0.005}}\,\text{mm}\]

\end{document} 

enter image description here

Bernard
  • 271,350