# Vertical alignment of equations including fractions in a table

I need to cramp a table into a tight space, but unfortunately the equations aren't aligning/fitting into it vertically. Here is the code:

\documentclass[12pt]{article}
\usepackage[a4paper, top = 0.8cm, left = 1cm, right = 1cm, bottom = 0.8cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{array}

\newcolumntype{C}{>{\centering\arraybackslash}m{#1}}

\begin{document}
\scriptsize
\tabcolsep=0.05cm
\setlength\extrarowheight{0.15cm}
\begin{tabular}{C{1.5cm}|C{1.5cm}|C{1.3cm}|C{4.4cm}|C{1.8cm}}
Querschnitt & Zug/Druck & Schub & Biegung & Torsion\\\hline
Spannung & $\sigma_w = \frac{F}{A_w}$ & $\tau_{w}= \frac{F_q}{A_w}$ & $\sigma_{wb} = \frac{M_{bx}}{W_{wbx}}$ &  $\tau_{wt} = \frac{M_t}{W_{wt}}$\\\hline
Rechteck & \multicolumn{2}{c|}{$A_w = 2a(b+t)$} & $W_{wbx} = \frac{(t+a)(b+a)^3-(t-a)(b-a)^3}{6(b+a)}$ &  $W_{wt} = 2abt$\\\cline{1-5}
Kreis & \multicolumn{2}{c|}{$A_w = \pi da$} & $W_{wb} = \frac{\pi\left[(d+a)^4 -(d-a)^4\right]}{32(d+a)}$ &  $W_{wt} = 2W_{wb}$\\
\end{tabular}
\end{document}


And what it currently looks like: As you can see, \extrarowheight fixed the issue of the equations overlapping the \hline on the top, but unfortunately they are still overlapping them on the bottom. In the document I'm using this table it also happens to be inconsistent for every cell, though I use the same snippet as added above.

Using m{} unfotunately didn't center the cells when using \extrarowheight, so I'm in some kind of dillema here as I can either center the equations or stop them from overlapping (on the top only). \arraystretch has the same effect as \extrarowheight.

Does anybody have a solution for this issue?

Thanks!

• Did you try https://tex.stackexchange.com/questions/6355/problem-with-table-vertical-alignment? – JPi May 7 '17 at 17:27
• @JPi Yep, this unfortunately breaks the equations though, even when making their cells way longer than they actually are. – Skydiver May 7 '17 at 17:31

You can insert "bottom [typographic] struts" to obtain more vertical whitespace between the lowest item in a formula and the horizontal line immediately below it.

• Provide some manual kerning for the 7 instances of W_{w...}.
• Since no linebreaks seem to be called for in any of the cells, you might was well use the basic c column type instead of a centered version of the p column type.
• Since the contents of almost all cells should be rendered in math mode, switching from a tabular environment to an array environment will save you from having to type lots and lots of $ tokens. \documentclass[12pt]{article} \usepackage[a4paper, vmargin = 0.8cm, hmargin = 1cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{array} % for "\extrarowheight" macro \newcommand\Bstrut{\rule[-1ex]{0pt}{0pt}} % "bottom" strut \begin{document} \noindent \scriptsize \setlength\arraycolsep{1mm} \setlength\extrarowheight{1.5mm}$\begin{array}{@{} >{$}c<{$} |c|c|c|c @{}} % first col. in text mode
Querschnitt & $Zug/Druck$ & $Schub$ & $Biegung$ & $Torsion$ \\
\hline
Spannung &
\sigma_w = \frac{F_{\vphantom{q}}}{A_{w\Bstrut}} &
\tau_{w}= \frac{F_{\!q}}{A_{w\Bstrut}} &
\sigma_{wb} = \frac{M_{bx}}{W_{\!wbx\Bstrut}} &
\tau_{wt} = \frac{M_t}{W_{\!wt\Bstrut}} \\
\hline
Rechteck &
\multicolumn{2}{c|}{A_w = 2a(b+t)} &
W_{\!wbx} = \frac{(t+a)(b+a)^3-(t-a)(b-a)^3}{6(b+a)\Bstrut} &
W_{\!wt\Bstrut} = 2abt \\
\cline{1-5}
Kreis &
\multicolumn{2}{c|}{A_w = \pi da} &
W_{\!wb} = \frac{\pi[(d+a)^{4} -(d-a)^4]}{32(d+a)} &
W_{\!wt} = 2W_{\!wb} \\
\end{array}$\end{document}  • Can I include your \Bstrut in my answer? – Moriambar May 7 '17 at 18:01 • @Moriambar - Absolutely! Please go ahead. – Mico May 7 '17 at 18:27 • Out of the proposed solutions the \Bstrut command was the most straight forward and easy to apply, so I ended up using it. Thank you! – Skydiver May 7 '17 at 19:00 I propose a "revolutionary" solution: \documentclass[12pt]{article} \usepackage[a4paper, top = 0.8cm, left = 1cm, right = 1cm, bottom = 0.8cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{multicol} \usepackage{booktabs} \usepackage{array} \newcommand\Bstrut{\rule[-0.6ex]{0pt}{0pt}} % "bottom" strut %\newcolumntype{Y}{>{\centering\arraybackslash}X} \begin{document} \scriptsize \tabcolsep=0.05cm \setlength\extrarowheight{0.15cm} \renewcommand{\arraystretch}{1.5} \begin{tabular}{l@{\qquad}c@{\qquad}c@{\qquad}c@{\qquad}c} \toprule Querschnitt & Zug/Druck & Schub & Biegung & Torsion\\ \midrule Spannung &$\sigma_w = \frac{F}{A_w}$&$\tau_{w}= \frac{F_q\Bstrut}{A_w}$&$\sigma_{wb} = \frac{M_{bx}\Bstrut}{W_{wbx}}$&$\tau_{wt} = \frac{M_t\Bstrut}{W_{wt}}$\\ Rechteck & \multicolumn{2}{c}{$A_w = 2a(b+t)$} &$W_{wbx} = \frac{(t+a)(b+a)^3-(t-a)(b-a)^3\Bstrut}{6(b+a)}$&$W_{wt} = 2abt$\\ Kreis & \multicolumn{2}{c}{$A_w = \pi da$} &$W_{wb} = \frac{\pi[(d+a)^4 -(d-a)^4]\Bstrut}{32(d+a)}$&$W_{wt} = 2W_{wb}$\\ \bottomrule \end{tabular} \end{document}  Yielding: What I did 1. Removed all the vertical separator. I think they are quite ugly and in the way of the text 2. Used some normal c-type columns, letting LaTeX determine the width of the specific columns 3. Inserte custom @{\qquad} spacing between some columns that were too much compressed (one can insert other spaces if he wants/deems them more readable) 4. Removed horizontal separators, which removed air from the equations, and replaced them with the booktabs rules (also: added booktabs) 5. Incremented the \arraystretch with \renewcommand{\arraystretch}{1.5} as a quick way to increment vertical spacing, in order to give space to the complex equations 6. Changed your \left[ ... \right] to the normal ones, to have correct spacings EDIT Also, thanks to the kind @Mico 1. Defined a new strut to lift some of the numerators with subscript, a little bit above the fraction line, with a command called \Bstrut. I also have used it where the parentheses were a bit close to the fraction line. • Instead of inserting a few \Bstrut directives in the first two rows, you could also provide \addlinespace directives after each line break, for more whitespace between the rows. – Mico May 7 '17 at 18:41 • I use Bstrut for space in math mode between the subscripts and the fraction line, not the hlines – Moriambar May 7 '17 at 18:44 • Thank you for making my table fancier, but unfortunately most of the changes required more space than I have available. I ended up removing the seperators and horizontal lines after seeing how much better it looks though! – Skydiver May 7 '17 at 19:01 with cellspace for more vertical space around cells' content and subdepth for better positioning of subscripts (indexes): \documentclass[12pt]{article} \usepackage[a4paper, vmargin = 0.8cm, hmargin = 1cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{cellspace} % for "\extrarowheight" macro \setlength\cellspacetoplimit{5pt} \setlength\cellspacebottomlimit{3pt} \usepackage[low-sup]{subdepth} % subscript positioning \begin{document} \noindent \scriptsize \setlength\tabcolsep{3pt} \begin{tabular}{@{} c|c|c|Sc|c @{}} Querschnitt & Zug/Druck & Schub & Biegung & Torsion \\ \hline Spannung &$\sigma_w = \frac{F}{A_{w}}$&$\tau_{w}
= \frac{F_{\!q}}{A_{w}}$&$\sigma_{wb}
= \frac{M_{bx}}{W_{\!wbx}}$&$\tau_{wt}
= \frac{M_t}{W_{\!wt}}$\\ \hline Rechteck & \multicolumn{2}{c|}{$A_w = 2a(b+t)$} &$W_{\!wbx}
= \frac{(t+a)(b+a)^3-(t-a)(b-a)^3}{6(b+a)}$&$W_{\!wt} = 2abt$\\ \cline{1-5} Kreis & \multicolumn{2}{c|}{$A_w = \pi da$} &$W_{\!wb} = \frac{\pi[(d+a)^{4} -(d-a)^4]}{32(d+a)}$&$W_{\!wt} = 2W_{\!wb}$\\ \end{tabular} \end{document}  Addendum: An alternative with considering Mico comment below and use amsmath package for \dfrac{...}{...} is: \documentclass[12pt]{article} \usepackage[a4paper, vmargin = 0.8cm, hmargin = 1cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{cellspace} % for "\extrarowheight" macro \setlength\cellspacetoplimit{5pt} \setlength\cellspacebottomlimit{3pt} \usepackage[low-sup]{subdepth} % subscript positioning \usepackage{amsmath} \begin{document} \noindent \scriptsize \setlength\tabcolsep{3pt} \begin{tabular}{@{} c|c|c|Sc|c @{}} Querschnitt & Zug/Druck & Schub & Biegung & Torsion \\ \hline Spannung &$\sigma_w = \dfrac{F}{A_{w}}$&$\tau_{w} = \dfrac{F_{q}}{A_{w}}$&$\sigma_{wb} = \dfrac{M_{bx}}{W_{wbx}}$&$\tau_{wt} = \dfrac{M_t}{W_{wt}}$\\ \hline Rechteck & \multicolumn{2}{c|}{$A_w = 2a(b+t)$} &$W_{wbx} = \dfrac{(t+a)(b+a)^3-(t-a)(b-a)^3}{6(b+a)}$&$W_{wt} = 2abt$\\ \cline{1-5} Kreis & \multicolumn{2}{c|}{$A_w = \pi da$} &$W_{wb} = \dfrac{\pi\left[(d+a)^{4} -(d-a)^4\right]}{32(d+a)}$&$W_{wt} = 2W_{wb}$\\ \end{tabular} \end{document} • This is pretty neat solution, unfortunately the code isn't working in my current document though (No issues in a fresh one). So while I'm not able to use it here, I'm surely going to apply this technique to future one! – Skydiver May 7 '17 at 19:03 • @Skydiver, the code is very standard. If you have in preamble of your document loaded in my MWE used packages (in comparison to your MWE is new only subdepth), the solution should work. Since your real preamble is not known, I can't see what could be cause of your problem. – Zarko May 7 '17 at 19:14 This fits the normal text width for article; using \mfrac from nccmath the fractions are not so unbearably small. \documentclass[12pt]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{array,booktabs} \usepackage{nccmath} \begin{document} \begin{table}[htp] \centering \footnotesize \addtolength{\tabcolsep}{-2pt} \begin{tabular}{@{}lcccc@{}} \toprule Querschnitt & Zug/Druck & Schub & Biegung & Torsion\\ \midrule Spannung &$\sigma_w = \mfrac{F}{A_w}$&$\tau_{w}= \mfrac{F_q}{A_w}$&$\sigma_{wb} = \mfrac{M_{bx}}{W_{wbx}}$&$\tau_{wt} = \mfrac{M_t}{W_{wt}}$\\ \addlinespace Rechteck & \multicolumn{2}{c}{$A_w = 2a(b+t)$} &$W_{wbx} = \mfrac{(t+a)(b+a)^3-(t-a)(b-a)^3}{6(b+a)}$&$W_{wt} = 2abt$\\ \addlinespace Kreis & \multicolumn{2}{c}{$A_w = \pi da$} &$W_{wb} = \mfrac{\pi\left[(d+a)^4 -(d-a)^4\right]}{32(d+a)}$&$W_{wt} = 2W_{wb}\$\\
\bottomrule
\end{tabular}

\end{table}

\end{document} 