5

I am using the code from egreg (a new command, xabove) from my previous question to typeset a "fraction" without the fraction bar.

In the following MWE, would there be a straightforward way to horizontally align the colons (:) in "A: 3.14" and "B: 6.28"? Or would I need to use a different definition of xabove?

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine} \usepackage{libertinust1math} \usepackage[T1]{fontenc} \usepackage[ expansion = false , tracking = smallcaps , letterspace = 40 , final ]{microtype} \usepackage{booktabs}

% egreg's answer (https://tex.stackexchange.com/a/590218/15622) \makeatletter \DeclareRobustCommand{\xabove}[2]{{% \mathpalette\fix@genfrac{{#1}{#2}}% }} \newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2} \newcommand{\fix@@genfrac}[3]{% \genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}% } \newcommand{\fix@@@genfrac}[1]{% \ifx#1\displaystyle 0pt\else \ifx#1\textstyle -\fontdimen8\textfont2 \else \ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else 0pt % but doesn't really work :-( \fi\fi\fi } \makeatother

\begin{document}

$\xabove{\textit{A}:;3.14}{\textit{B}:;6.28}$

\end{document}

mwe

Andrew
  • 1,249
  • 1
    Use an array. – egreg Mar 29 '21 at 16:56
  • 1
    @egreg Since I thought the same thing, but obviously you preceded me :-), here is another shameful but working solution: $\xabove{\textit{\makebox[3mm]{A:}}\;3.14}{\textit{\makebox[3mm]{B:}}\;6.28}$ – Ivan Mar 29 '21 at 17:00

3 Answers3

4

An aligned TABstack can do the job. Here I choose a (user-selectable) 2.5pt gap between rows of the stack which I believe fits and does not force a larger interline gap in the text.

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine} \usepackage{libertinust1math} \usepackage[T1]{fontenc} \usepackage[ expansion = false , tracking = smallcaps , letterspace = 40 , final ]{microtype} \usepackage{booktabs}

\usepackage{tabstackengine,lipsum} \TABstackMath \TABstackMathstyle{\scriptstyle} \begin{document} \lipsum[1] \alignstackanchor[2.5pt]{A:&;3.14}{B:&;6.28} % FOR S \stacktype \lipsum[2] \end{document}

enter image description here

3

You can do it, but you should think whether this is really what you want.

\documentclass[oneside,10pt]{book}
\usepackage{amsmath,mathtools}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[T1]{fontenc}

\makeatletter \DeclareRobustCommand{\xabove}[2]{{% \mathpalette\fix@genfrac{{#1}{#2}}% }} \newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2} \newcommand{\fix@@genfrac}[3]{% \genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}% } \newcommand{\fix@@@genfrac}[1]{% \ifx#1\displaystyle 0pt\else \ifx#1\textstyle -\fontdimen8\textfont2 \else \ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else 0pt % but doesn't really work :-( \fi\fi\fi } \newcommand{\labeledabove}[4]{% \xabove{\above@label{#1}{#3}{:};\hfill#2}{\above@label{#3}{#1}{:};\hfill#4}% } \newcommand{\above@label}[2]{\mathpalette\above@@label{{#1}{#2}}} \newcommand{\above@@label}[2]{\above@@@label#1#2} \newcommand{\above@@@label}[3]{% {\sbox\z@{\vbox{\ialign{$\m@th#1##\mkern-2mu$\hfil\cr#2\cr#3\cr}}}\makebox[\wd\z@][l]{$\m@th#1#2$}} } \makeatother

\begin{document}

$\displaystyle\frac{1}{2}\xabove{1}{2}$

$\textstyle\frac{1}{2}\xabove{1}{2}$

$\scriptstyle\frac{1}{2}\xabove{1}{2}$

%$\scriptscriptstyle\frac{1}{2}\xabove{1}{2}$

\bigskip

$\displaystyle\labeledabove{A}{3.14}{B}{6.28}\quad\xabove{1}{2}$

\medskip

$\labeledabove{A}{3.14}{B}{6.28}\quad\xabove{1}{2}$

\end{document}

enter image description here

egreg
  • 1,121,712
3

Here is a straight-forward way via \phantom:

enter image description here

\documentclass{article}

\usepackage[semibold,tt=false]{libertine} \usepackage{libertinust1math} \usepackage[T1]{fontenc} \usepackage{mathtools}

% egreg's answer (https://tex.stackexchange.com/a/590218/5764) \makeatletter \DeclareRobustCommand{\xabove}[2]{{% \mathpalette\fix@genfrac{{#1}{#2}}% }} \newcommand{\fix@genfrac}[2]{\fix@@genfrac#1#2} \newcommand{\fix@@genfrac}[3]{% \genfrac{}{}{\fix@@@genfrac{#1}}{}{#2}{#3}% } \newcommand{\fix@@@genfrac}[1]{% \ifx#1\displaystyle 0pt\else \ifx#1\textstyle -\fontdimen8\textfont2 \else \ifx#1\scriptstyle -\fontdimen8\scriptfont2 \else 0pt % but doesn't really work :-( \fi\fi\fi } \makeatother

\begin{document}

$\xabove{\textit{A}:;3.14}{\phantom{\textit{A}}\mathllap{\textit{B}}:;6.28}$

\end{document}

This works because A and B are the only two things that have differing widths in the top/bottom. So we place the wider/larger inside a \phantom to achieve the desired placement/position and then insert the other (narrower/smaller) component in via \mathllap (from mathtools).

Werner
  • 603,163