In math mode, how do I make the fraction bar "invisible"?

I am trying to typeset a "fraction" without the fraction bar. I have tried to do this using the genfrac, but as in the example below, the numerator and denominator in genfrac are farther apart than in frac. How can I correct this?

I'm trying to create a table in which one of the entries ("cells") contains two entries -- one on top of the other -- as in row 5 in the MWE below. In other words, I want to make the fraction bar "invisible" in the MWE table below.

\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[subrefformat=parens]{subcaption}

\begin{document}

$\frac{1}{2}\;\genfrac{}{}{0pt}{}{1}{2}$

\begin{table}[!h]
\begin{tabular}{lll}
Row 1 & 1.23 & Some text.\\
Row 2 & 7.89 & Additional text.\\
Row 3 & 4.56 & More text.\\
Row 4 & 1.23 & Some text.\\
Row 5 & $\frac{\textit{A}:\;3.14}{\textit{B}:\;6.28}$ & Additional text.\\
Row 6 & 4.56 & More text.\\
\end{tabular}
\end{table}

\end{document}


• Just to make sure, you are aware that the usual approach is a row spanning multirow? But this makes "Row 5" and "Additional text." twice as tall instead of the other entry half-sized. Mar 26, 2021 at 21:16

That's a bit unexpected, I'll have to read appendix G again... but \genfrac is just exposing the underlying primitive and \atop and \above0pt both omit the rule but increase the height of the numerator. You can specify the negative width of the default rule (-0.4pt) to get the same height as \frac (which uses the \over primitive).

The first four forms here use the same height as\frac, the last three are higher.

Note this only applies to textstyle not displaystyle.

\documentclass[oneside,10pt]{book}
\usepackage{amsmath}

\usepackage[T1]{fontenc}

\begin{document}

\hrule
$\frac{1}{2}\; \genfrac{}{}{-.4pt}{}{1}{2}\; {1 \above -.4pt 2}\; {1\over 2}\; {1 \above 0pt 2}\; \genfrac{}{}{0pt}{}{1}{2}\; {1\atop 2}$
\hrule
\smallskip
\hrule
$\displaystyle \frac{1}{2}\; \genfrac{}{}{-.4pt}{}{1}{2}\; {1 \above -.4pt 2}\; {1\over 2}\; {1 \above 0pt 2}\; \genfrac{}{}{0pt}{}{1}{2}\; {1\atop 2}$
\hrule

\end{document}


The \frac macro is defined as \begingroup #1\endgroup \over #2 (for the definition enter texdef -t latex \frac in a terminal). You can redefine this to print the \over line in white:

\newcommand{\fracnoline}[2]{{\begingroup #1\endgroup \color{white}\over\color{black} #2}}


As Mico noted in comments, to generalize the macro in case the original color is not black you can use the following definition:

\newcommand{\fracnoline}[2]{\colorlet{foo}{.}{\begingroup #1\endgroup \color{white}\over\color{foo} #2}}


Full code:

\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[subrefformat=parens]{subcaption}
\usepackage{xcolor}

\begin{document}
\newcommand{\fracnoline}[2]{\colorlet{foo}{.}{\begingroup #1\endgroup \color{white}\over\color{foo} #2}}

$\frac{1}{2}\;\genfrac{}{}{0pt}{}{1}{2}$

\begin{table}[!h]
\begin{tabular}{lll}
Row 1 & 1.23 & Some text.\\
Row 2 & 7.89 & Additional text.\\
Row 3 & 4.56 & More text.\\
Row 4 & 1.23 & Some text.\\
Row 5 & $\frac{\textit{A}:\;3.14}{\textit{B}:\;6.28} \fracnoline{\textit{A}:\;3.14}{\textit{B}:\;6.28}$ & Additional text.\\
Row 6 & 4.56 & More text.\\
\end{tabular}
\end{table}

\end{document}


Result:

– Mico
Mar 26, 2021 at 22:36
• @Mico thanks for your comment, I added it to the answer. Mar 27, 2021 at 12:22

With amsmath you can use the \substack command:

\documentclass[oneside,11pt]{book}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

\begin{table}[!h]
\begin{tabular}{lll}
Row 1 & 1.23 & Some text.\\
Row 2 & 7.89 & Additional text.\\
Row 3 & 4.56 & More text.\\
Row 4 & 1.23 & Some text.\\
Row 5 & $\substack{\textit{A}:\;3.14\\[1pt]\textit{B}:\;6.28}$ & Additional text.\\
Row 6 & 4.56 & More text.\\
\end{tabular}
\end{table}

\end{document}


• The correct answer IMO, don't abuse a fraction to do this.
– BrtH
Mar 27, 2021 at 16:55
• If you post that as an asnwer I can upvote it. I do agree. For tables, use table tools. Mar 30, 2021 at 23:51

Starting from David's answer, a fixed version that works in display, text and script style (not at scriptscript style, where other optimizations are used).

\documentclass[oneside,10pt]{book}
\usepackage{amsmath}
\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
}
\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}$

\end{document}