[Tex/LaTex] A “fraction” with three stories and two bars (of equal length)

math-mode

I'd like to create a document containing "fractions" with three or more stories instead of just two, separated by fraction bars of equal length. (These aren't real fractions, but I want to use fraction bars for the notation.)

Two things I've tried are the matrix environment with \hlines, and simply nesting \fracs. Neither one produces a satisfactory result:

Two three-story fraction workarounds

The matrix option, on the left, looks pretty decent, but the \hlines are far too wide; they should be barely wider than each story of the fraction. With the nested \frac option, however, the two bars are of slightly different widths, the entire fraction has incorrect vertical positioning (it's centered on the lower bar, instead of the center story), and the vertical spacing is dubious.

\begin{matrix}
N I \\ \hline
I N \\ \hline
a I
\end{matrix}
= \frac{\dfrac{I a}{\N I}}{I N}

Is there a nice way to get multi-story fractions?

Best Answer

Environment array can be used:

\documentclass{article}

\newcommand*{\threefrac}[3]{%
  \begin{array}{@{\,}c@{\,}}%
    #1\\
    \hline
    #2\\
    \hline
    #3%
  \end{array}%
}

\begin{document}
\[
  \threefrac{NI}{IN}{aI} = \threefrac{Ia}{NI}{IN}
\]
\end{document}

Result

The lines are longer on each sides by a thin space (\,). This can be changed, if the lines should be smaller or larger.

Uniform spacing around the lines

Here a variant with uniform line spacing using \halign. The vertical space can be configured by redefining \threefracLineSep.

\documentclass{article}

\newcommand*{\threefrac}[3]{%
  \ensuremath{%
    \vcenter{%
      \halign{\hfil$\,##\,$\hfil\cr
        #1\cr
        \noalign{\kern\threefracLineSep}%
        \hline
        \noalign{\kern\threefracLineSep}%
        #2\cr
        \noalign{\kern\threefracLineSep}%
        \hline
        \noalign{\kern\threefracLineSep}%
        #3\cr
      }%
    }%  
  }%
}
\newcommand*{\threefracLineSep}{.4ex}

\begin{document}
\[
  \threefrac{NI}{IN}{aI} = \threefrac{Ia}{NI}{IN}
  \neq \threefrac{\sum\limits_{n=1}^\infty NI^n}{\dots}{n}
\]
\end{document}

Result

Related Question