8

I need to typset a series of fractions with no line inside some paragraphs of text (they were used as proportional symbols). It is very simple, actually:

$^2_1$, $^4_2$,$^8_4$

But when it comes to $^{12}_{6}$, the two numbers are not aligned vertically.

If I use a fraction $\frac{12}{6}$ the alignment is good, but the horizontal line shouldn't be there.

Any suggestions?

Thank you, A

\documentclass{article}
\begin{document}

I need this $^{12}_{6}$ aligned vertically like this $\frac{12}{6}$.

\end{document}

Following all answers, I have to say all of them work fine, but they do not produce a result which is identical to $^{12}_{6}$. The problem arises when you have more than one instance in the same context, and I believe the $^{12}_{6}$ spacing is the optimal one. See the picture:

\documentclass{article}


\newcommand{\myfrac}%  % macro with LaTeX-style syntax
    [2]{\begin{array}{@{}c@{}}\scriptstyle #1 \\[-1.2ex]\scriptstyle #2\end{array}}
\begin{document}

\noindent Myfrac plus smash as by the example by Harish and Harold compared with optimal vertical spacing: $^{1}_{2}$, \smash{$\myfrac{22}{6}$}, $^{4}_{2}$, $^{2}_{1}$; can you see the difference? My proofreader will kill me, my proofreader will kill me, my proofreader will kill me :-).


\end{document}  

The 2 in the second fraction is positioned lower

user56153
  • 999
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. You might also want to add to your question how you're including the pdfs etc. – Aradnix Sep 05 '14 at 05:09

7 Answers7

8

In a similar way to how one can define Sterling numbers of the second kind, amsmath's \genfrac can be used to set a fraction that has no horizontal line:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\psymbol}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
\newcommand{\tpsymbol}[2]{\genfrac{}{}{0pt}{1}{#1}{#2}}
\newcommand{\dpsymbol}[2]{\genfrac{}{}{0pt}{0}{#1}{#2}}
\begin{document}
It's easy to see that $\psymbol{a}{b}$ and $\frac{a}{b}$ is always $\tpsymbol{2}{1}$ and $\tfrac{2}{1}$ and sometimes
$\psymbol{12}{6}$ and $\frac{12}{6}$. Also,
\[
  f(x,y) = \psymbol{36}{18}\ \frac{36}{18} \quad \text{while} \quad g(x) = \tpsymbol{108}{54}\ \tfrac{108}{54}.
\]
Maybe one can also define $\begin{smallmatrix}16 \\ 8\end{smallmatrix}$ and $\frac{16}{8}$.
\end{document}

amsmath also offers smallmatrix that can be used to set a similar vertically stacked structure.

Werner
  • 603,163
8

There is a TeX math-mode primitive called \atop that does exactly what you need. However, it uses so-called infix notation and is not widely used in LaTeX. Fortunately, it's not difficult to create a LaTeX-style macro called, say, \myatop that mimics the syntax of the LaTeX macro \frac. In fact, the construction of the \myatop macro in the example below is exactly analogous to to the construction of the LaTeX macro \frac.

The following code shows the results of this using this macro, as well as the plain-TeX \atop macro and the \frac macro. (Thanks to the great suggestion by @wipet, the upper number using \atop is now at the same height as it would be when using \frac when used in inline math mode.)

enter image description here

\documentclass{article}
\newcommand{\myatop}[2]{%  % a macro with LaTeX-style syntax
    \fontdimen10\textfont2=\fontdimen9\textfont2% using wipet's suggestion
    {\begingroup#1\endgroup\atop#2}}    
\begin{document}
inline math mode:\quad ${22\atop 6} \quad \myatop{22}{6} \quad \frac{22}{6}$

\bigskip

display math mode: $\displaystyle {22\atop6} \quad \myatop{22}{6} \quad \frac{22}{6} $
\end{document}
Mico
  • 506,678
  • This would be a good solution, but the numbers appear too far from each other. – user56153 Sep 05 '14 at 06:00
  • @user56153 - glad you found my proposed solution good . :-) By the way, the vertical separation generated by \atop is identical to that generated by \genfrac in the accepted answer. – Mico Sep 05 '14 at 06:22
  • See the last example with $\begin{smallmatrix}16 \ 8\end{smallmatrix}$. It has the right separation space between the numbers, but it's got too much white space before and after the fraction. – user56153 Sep 05 '14 at 07:12
  • 4
    Note: \atop generates numerator to higher place in text style than normal fraction by \over (your picture is clear). The reason is that \atop uses \fontdimen10\font2 but \over uses \fontdimen9. See TeXbook p. 444, rule 15b. If you need to correct this, you can type (in plain TeX) \fontdimen10\textfont2=\fontdimen9\textfont2 but this doesn't work in LaTeX because of silly NFSS. You have to put this in \everymath or use trick with negative thickness of the rule: {22 \above-1pt 6}. – wipet Sep 05 '14 at 14:57
  • @wipet - Many thanks for these very detailed comments and suggestions! I've followed your suggestion to use \everymath to effect the reset of \fontdimen10 and posted a new MWE and graph. – Mico Sep 05 '14 at 18:26
  • @user56153 - I've modified the code to address your concern that the upper number is set too high when using \atop. (wipet's suggestions were perfect.) – Mico Sep 05 '14 at 18:27
5

Why not use an array or tabular?

\documentclass{article}
\newcommand{\myfrac}%  % macro with LaTeX-style syntax
    [2]{\begin{array}{@{}c@{}}#1 \\[-0.75ex]#2\end{array}}
\begin{document}
 $\myfrac{22}{6}$, and $\myfrac{22}{6}$
\end{document}

enter image description here

If you want it to be small:

\documentclass{article}
\newcommand{\myfrac}%  % macro with LaTeX-style syntax
    [2]{\begin{array}{@{}c@{}}\scriptstyle #1 \\[-1.2ex]\scriptstyle #2\end{array}}
\begin{document}
 $\myfrac{22}{6}$, and $\myfrac{22}{6}$

 I need this $\myfrac{12}{6}$ aligned vertically like this $\frac{12}{6}$.
\end{document}

enter image description here

Here is a smaller version:

\documentclass{article}


\newcommand{\myfrac}%  % macro with LaTeX-style syntax
    [2]{\raise.12ex\hbox{$\begin{array}{@{}c@{}}\scriptstyle #1 \\[-1.35ex]\scriptstyle #2\end{array}$}}
\begin{document}

\noindent Myfrac plus smash as by the example by Harish and Harold compared with optimal vertical spacing: $^{1}_{2}$, \smash{$\myfrac{22}{6}$}, $^{22}_{6}$, $^{2}_{1}$; can you see the difference? My proofreader will kill me, my proofreader will kill me, my proofreader will kill me :-).


\end{document}

enter image description here

  • This solution would be good, but it is too large in height, so that it affects the paragraph height of my text. – user56153 Sep 05 '14 at 06:02
  • In your smaller version the space between numbers is correct, but if you put this code in a typeblock, you will end up with too much space between two lines of the pargraph. Plus, the numbers are smaller than $^12_&$. – user56153 Sep 05 '14 at 07:15
  • @user56153 See the update. Is that OK? –  Sep 05 '14 at 07:44
  • @user56153 If you want to avoid effect to the paragraph height, you can also \smash{} it :) – Harald Sep 05 '14 at 07:58
  • Harish and Harald, thank you for your suggestions, but see my question edits. – user56153 Sep 05 '14 at 11:05
  • @user56153 See the update. –  Sep 05 '14 at 11:16
  • Harish, so the solution was to introduce \raise.12ex. Thank you so much, now my proofreader won't kill me anymore :-). – user56153 Sep 05 '14 at 11:40
  • We are talking about such -1.35ex as a Pisvejc number. It means number fallen from heavens. See my answer which simulates exactly the ^ and _. – wipet Sep 06 '14 at 06:01
5

You can use the subarray environment of amsmath, that also allows left alignment:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\pseudofrac}[2]{%
  \begin{subarray}{l}#1\\#2\end{subarray}%
}

\begin{document}

I need this $\pseudofrac{12}{6}$ aligned vertically like this $\frac{12}{6}$.

\end{document}

enter image description here

egreg
  • 1,121,712
4

The harmony package creates very tightly spaced, vertically aligned and centered numerals with the \Takt command. It is intended for time signatures in musicological writing (Takt is German for "measure" or "time").

\documentclass{article}
\usepackage[rm]{harmony} 
    % rm option uses the roman family instead of the default sans-serif

\begin{document}

\Takt{12}{6}

\Takt{135}{222}

\Takt{3}{1478}

\end{document}

enter image description here

musarithmia
  • 12,463
4

The question includes: "If I use a fraction $\frac{12}{6}$ the alignment is good, but the horizontal line shouldn't be there." This is the reason why there are answers which emulates exactly fraction but without line. After edit of the question, we can read:"the answers do not produce a result which is identical to $^{12}_{6}$". Of course, this was not in the first placing. But we can do this if we know, what exacly does the ^ and _. We can emulate this work by \halign.

% \cei^{exp}_{ind} = Center Exponent and Index
\def\cei^#1_#2{\lower\fontdimen17\textfont2\vbox{%
   \baselineskip=\fontdimen17\textfont2 \advance\baselineskip by\fontdimen14\textfont2
   \halign{\hfil$\scriptstyle##$\hfil\cr#1\cr#2\cr}%
}}

You can add this code before \begin{document} (if you are using LaTeX) and you can type in your document:

... $^{1}_{2}$, $\cei^{22}_{6}$, $^{4}_{2}$, $^{2}_{1}$; ...

cei

wipet
  • 74,238
3

A solution that relies on the stackengine package. I define a \varfrac command in math mode and a \varfractextcommand for textmode. An optional argument is the vertical spacing between the numerator and denominator (separated by \\), that defaults to 8pt.

Depending on the contents of the fraction you may reduce or increase this spacing. Another way of adjusting would be to slighltly increase the value of \baselinestretch for the whole document, as vertical spacing defined by LaTeX is really tight. I give an example where I increase the value of \baselineskip by 6 %, with the help of the setspace package:

\documentclass{article}
\usepackage[utf8]{inputenc}

\newcommand{\myfrac}% % macro with LaTeX-style syntax
    [2]{\begin{array}{@{}c@{}}\scriptstyle #1 \\[-1.2ex]\scriptstyle #2\end{array}}

\usepackage{stackengine}
\setstackEOL{\\}
\newcommand\varfractext[2][8pt]{\smash{\setstackgap{L}{#1}\scriptsize\Centerstack{#2}}}
\newcommand\varfrac[2][8pt]{\smash{\setstackgap{L}{#1}\ensurestackMath{\everymath{\scriptstyle}\Vectorstack{#2}}}}
\usepackage{setspace}

\begin{document}

\noindent \verb+\Myfrac+ plus \verb+\smash+ as by the example by Harish and Harold compared with optimal vertical spacing: $^{1}_{2}$, \smash{$\myfrac{22}{6}$}, $^{4}_{2}$, $^{2}_{1}$; can you see the difference? My proofreader will kill me, but my proofreader won't kill me anymore with $ \pi \approx\varfrac{22\\7} $ or better (textmode): \varfractext{355\\113}\enspace \varfractext[6pt]{355\\113}, my proofreader won't kill me anymore, my proofreader won't kill me me anymore:-).\bigskip

\noindent With \verb+\setstretch{1.06}+:\\[1ex]
\verb+\Myfrac+ plus \verb+\smash+ as by the example by Harish and Harold compared with optimal vertical spacing: $^{1}_{2}$, \smash{$\myfrac{22}{6}$}, $^{4}_{2}$, $^{2}_{1}$; can you see the difference? My proofreader will kill me, but my proofreader won't kill me anymore with $ \pi \approx\varfrac{22\\7} $ or better (textmode): \varfractext{355\\113}\enspace \varfractext[6pt]{355\\113}, my proofreader won't kill me anymore, my proofreader won't kill me me anymore:-).

\end{document} 

enter image description here

Bernard
  • 271,350
  • Thank you, Bernard, your answer is really interesting. Now I just have to choose between many very good options. – user56153 Sep 05 '14 at 17:37
  • @Mico: Not sure your question is for me. I wonder if you mean \myfrac or \varfrac(text). I'm only wrote the latter, and I guess it could work as you ask, using \mathchoice. – Bernard Sep 05 '14 at 19:01