8

I want to know how to precisely configure the vertical alignment of equations in tabular, for example, \arraystretch can increase the height but cannot make equations vertically centered, their baseline is too low. Also, inline equations and display-style equations can be both well aligned.

\documentclass{article}
\usepackage{amsmath}
\def\arraystretch{2.5}

\begin{document}

\begin{center} \begin{tabular}{|c|c|} \hline $a + b = c$ & inline style \ \hline $e + \dfrac{\mathrm{d}f}{\mathrm{d}x} + \dfrac{\mathrm{d}f}{\mathrm{d}y} + \dfrac{\mathrm{d}f}{\mathrm{d}z} = 0$ & display style \ \hline \end{tabular} \end{center}

\end{document}

enter image description here

5 Answers5

6

With tabularray:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}

\begin{center} \begin{tblr}{hlines, vlines, colspec = {Q[c, mode=math] l}, rowsep = {5pt} } a + b = c & inline style \ e + \dfrac{\mathrm{d}f}{\mathrm{d}x} + \dfrac{\mathrm{d}f}{\mathrm{d}y} + \dfrac{\mathrm{d}f}{\mathrm{d}z} = 0 & display style \ \end{tblr} \end{center}

\end{document}

enter image description here

Zarko
  • 296,517
6

A solution with the cellspace package, which allows to define a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (or Cif you load siunitx, or any letter you please with a loading time option). I also loaded the esdiff package to simplify the code for derivatives in Leibniz notation.

    \documentclass{article}
    \usepackage{amsmath}
    \usepackage{esdiff}
    \usepackage{cellspace}
    \setlength{\cellspacetoplimit}{6pt}
    \setlength{\cellspacebottomlimit}{6pt}
\begin{document}

\begin{center}
    \begin{tabular}{|Sc|Sc|}
        \hline
        $a + b = c$ & inline style \\
        \hline
        $e + \diff{f}{x} + \diff{f}{y} + \diff{f}{z} = 0$ & display style \\
        \hline
    \end{tabular}
\end{center}

\end{document}

enter image description here

Bernard
  • 271,350
5

An answer with easytable:

\documentclass{article}
\usepackage{amsmath}
\usepackage[thinlines]{easytable}

\begin{document}

\begin{center} \begin{TAB}(r,1cm,2cm)[5pt]{|c|c|}{|c|c|}% (rows,min,max)[tabcolsep]{columns}{rows} $a + b = c$ & inline style \ $e + \dfrac{\mathrm{d}f}{\mathrm{d}x} + \dfrac{\mathrm{d}f}{\mathrm{d}y} + \dfrac{\mathrm{d}f}{\mathrm{d}z} = 0$ & display style \ \end{TAB} \end{center}

\end{document}

Source: https://tex.stackexchange.com/a/159263/120578

Output:

enter image description here

koleygr
  • 20,105
5

arraystretch causes asymmetric stretching. This effect is more visible the higher is its factor. It's better to use struts to add vertical spacing in rows

enter image description here

\documentclass{article}
\usepackage{array,mathtools}

\DeclareMathOperator\od{\mathrm{d}!}

\begin{document} \bgroup \centering [ \begin{array}{| c | c |} \hline \xmathstrut{0.5} a + b = c & \textrm{inline style} \ \hline \xmathstrut{1.25} e + \dfrac{\od f}{\od x} + \dfrac{\od f}{\od y} + \dfrac{\od f}{\od z} = 0 & \textrm{display style} \ \hline \end{array} ] \egroup \end{document}

Celdor
  • 9,058
4

With {NiceTabular} of nicematrix, you have a key cell-space-limits for address that problem.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center} \begin{NiceTabular}{|c|c|}[cell-space-limits=6pt] \hline $a + b = c$ & inline style \ \hline $e + \dfrac{\mathrm{d}f}{\mathrm{d}x} + \dfrac{\mathrm{d}f}{\mathrm{d}y} + \dfrac{\mathrm{d}f}{\mathrm{d}z} = 0$ & display style \ \hline \end{NiceTabular} \end{center}

\end{document}

Output of the above code

F. Pantigny
  • 40,250