4

I'm having a hard time trying to get a properly aligned inequations involving fractions in KaTeX. The best output I have got is with the array environment:

\begin{array}{crccclc}
z\in\Bbb R^+, & 0 &\le& x-z\ffrac{x}{z} &\lt& z & (8)\\[3pt]
& z\ffrac{x}{z} &\le& x &\lt& (z+1)\ffrac{x}{z}  &(9)
\end{array}

enter image description here

The problem is the array environment displays formulas in inline style. How could I force arrays to print fractions, sums, etc, in a non-inline style so they take more height?

6
  • The horizontal spacing is not good.
    – Bernard
    Commented Feb 5, 2021 at 22:53
  • @Sebastiano I know. Does this site allow questions abouts KaTeX?
    – ABu
    Commented Feb 5, 2021 at 23:03
  • 1
    @Sebastiano Thanks, I didn't know mathjax and KaTeX were the same thing, although I knew they are, strictly spoken, different from LaTeX/TeX.
    – ABu
    Commented Feb 5, 2021 at 23:06
  • 1
    @Sebastiano katex-specific questions, like mathjax-specific questions are off topic (as they are javascript) but if the question can be phrased so it also applies to latex it can of course be on topic. Commented Feb 5, 2021 at 23:51
  • @Sebastiano your comment is basically misleading. Commented Feb 5, 2021 at 23:59

4 Answers 4

4

For those who don't use KaTeX, here's an answer that use the alignat environment of the amsmath environment.

enter image description here

\documentclass{article}
\usepackage{array,amssymb,mathtools}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\newcommand\ffrac[2]{\floor*{\frac{#1}{#2}}}
\newlength\mylen
\settowidth\mylen{$\displaystyle x-z\ffrac{x}{z}$} % measure width of middle part

\begin{document}
\begin{alignat}{4}
z\in\Bbb{R}^+, &\quad& 0 &\le{}&& x-z\ffrac{x}{z} &{}<{}& z \\[1ex]
               && z\ffrac{x}{z} &\le{}&& \parbox{\mylen}{\centering$x$} &{}<{}& (z+1)\ffrac{x}{z} 
\end{alignat}
\end{document}
3
  • How did you add the formula numbering at the end of each line? Does alignat add them automatically in LaTeX? KaTeX have a similar environment called alignedat but it doesn't add them.
    – ABu
    Commented Feb 5, 2021 at 23:16
  • 2
    @Peregring-lk - I'm afraid I'm not familiar with KaTeX. The amsmath package provides environments called align, alignat, aligned, and alignedat. The former two are standalone environments that provide equation numbering; the latter two are meant to be used inside a larger, encasing environment and do not provide their own numbering mechanism.
    – Mico
    Commented Feb 5, 2021 at 23:20
  • Don't be afraid.
    – ABu
    Commented Feb 5, 2021 at 23:22
4

A variant of @Mico's solution, using the \DeclarePairedDelimiterX command, from mathtools:

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\DeclarePairedDelimiterX{\ffrac}[2]{\lfloor}{\rfloor}{\frac{#1}{#2}}

\begin{document}

\setcounter{equation}{7}

\begin{alignat}{3}
z\in\Bbb R^+, \qquad 0 &\le x- & & z\ffrac*{x}{z} & & < z \\[3pt]
 z\ffrac*{x}{z} &\le & & x & & < (z+1)\ffrac[\bigg]{x}{z}
\end{alignat}

\end{document} 

enter image description here

2

I just found out that KaTeX has the darray environment that does exactly what I'm asking for.

2
  • 3
    @Sebastiano mathjax and katex are not related. Commented Feb 6, 2021 at 0:00
  • @DavidCarlisle Hi, I delete my comments on KaTeX.
    – Sebastiano
    Commented Feb 6, 2021 at 8:09
2

I add a small answer (it similar to a comment). I suggest to use this link https://katex.org/docs/support_table.html, a simple guide of KaTeX specific for the table.


enter image description here


\begin{darray}{cc}
   a & b \\
   c & d
\end{darray}

In the left bar you can find also the guide of KaTeX. I add also a link of MathJaX that it is used in Math.SE:

https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .