# Fitting a large equation with gathered in table cell

I currently have a table and two equations like this:

\documentclass[a4paper,12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage[stable]{footmisc}
\usepackage[justification=centering]{caption}
\onehalfspacing
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

%center align fixed width column
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\date{}
\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{|P{6 cm}|P{2.7 cm}|c|P{2 cm}|P{2 cm}|}
\toprule
\textbf{Model} & \textbf{Research Question} & \textbf{Coefficient} & \textbf{Response A} & \textbf{Response B} \\ \hline
\multirow{ 2}{*}{Model 7} & RQ1a & \delta_{1} & $−.094^{***}$ $(.017)$ & $−0.458^{***}$ $(0.067)$ \\\cline{2-5}
& RQ1b & \delta_{2} & $−.091^{***}$ (−.020) & $−0.210^{**}$ (0.039)\\ \hline
\multirow{ 2}{*}{Model 8} & RQ2 & \delta_{1} & $−.020$ $(.014)$
& $0.039$ $(0.055)$ \\\cline{2-5}
& RQ2 & \delta_{2} & $.023^{\dagger}$ $(.014)$ & $0.209^{***}$ $(0.053)$ \\ \hline
\end{tabular}
\caption{Caption}
\label{table2}
\end{table}
\noindent\textit{Note:} Unstandardized coefficients with corrected standard errors in parentheses.\\
$^{\dagger}$  p < .10, $^{*}$ p < .05, $^{**}$ p < .01, $^{***}$ p <  .001.

$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$

$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$
\clearpage

\end{document}


And it looks like:

However, I would love to have the equations in the cell as well (in place of the words Model 1 and 2).

When I replace the words with the whole equations, my table looks ugly:

The code for that is as follows:

\documentclass[a4paper,12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage[stable]{footmisc}
\usepackage[justification=centering]{caption}
\onehalfspacing
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

%center align fixed width column
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\date{}
\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{|P{6 cm}|P{2.7 cm}|c|P{2 cm}|P{2 cm}|}
\toprule
\textbf{Model} & \textbf{Research Question} & \textbf{Coefficient} & \textbf{Response A} & \textbf{Response B} \\ \hline
\multirow{ 2}{*}{$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \\ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \\ \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$} & RQ1a & \delta_{1} & $−.094^{***}$ $(.017)$ & $−0.458^{***}$ $(0.067)$ \\\cline{2-5}
& RQ1b & \delta_{2} & $−.091^{***}$ (−.020) & $−0.210^{**}$ (0.039)\\ \hline
\multirow{ 2}{*}{$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \\ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \\ \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$} & RQ2 & \delta_{1} & $−.020$ $(.014)$
& $0.039$ $(0.055)$ \\\cline{2-5}
& RQ2 & \delta_{2} & $.023^{\dagger}$ $(.014)$ & $0.209^{***}$ $(0.053)$ \\ \hline
\end{tabular}
\caption{Caption}
\label{table2}
\end{table}
\noindent\textit{Note:} Unstandardized coefficients with corrected standard errors in parentheses.\\
$^{\dagger}$  p < .10, $^{*}$ p < .05, $^{**}$ p < .01, $^{***}$ p <  .001.
\clearpage

\end{document}


I want the rows to become wider to fit the equations. How can I go about doing that?

EDIT: @koleygr's answer doesn't quite work for me. I get

Some of the column dividers aren't complete, and all the cell values are not equally padded on all sides (looks inconsistent).

As for @Mico's answer, the equations I gave were sample equations. A longer equation doesn't fit in the cells.

• Could you pleas show how you achieved the output in the second Screenshot? As far as I can tell, the current MWE will result in the first image. Also, do you still want your equations to be numbered? Nov 7, 2019 at 19:42
• @leandriis added the code for the second one as well. Yes, I would ideally like my equations to be numbered, but not if it's a huge problem. Nov 7, 2019 at 19:58
• @wrahool ... in my solution add bigger spaces (in the code \\[+0.6cm])... You have to manually find the appropriate added height. Nov 7, 2019 at 22:28
• You noted, "A longer equation doesn't fit in the cells." I was just working with the material you provided. Do take the time to learn how to use the aligned and gathered environment. (The benefits will be substantial...)
– Mico
Nov 8, 2019 at 6:36

Just an idea that avoids multirow :

\documentclass[a4paper,12pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{array}

\usepackage[stable]{footmisc}
\usepackage[justification=centering]{caption}
%\onehalfspacing
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

%center align fixed width column
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\date{}
\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{|P{6.5 cm}|@{}P{2.7 cm}|P{2.15cm}|P{2 cm}|P{2 cm}@{}|}
\hline
\textbf{Model} & \textbf{Research Question} & \textbf{Coefficient} & \textbf{Response A} & \textbf{Response B} \\ \hline
\parbox{6.5cm}{$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \\ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \\ \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$} &\begin{tabular}{@{}P{2.7 cm}P{2.15cm}|P{2 cm}|P{2 cm}@{}|} RQ1a & $\delta_{1}$ & $-.094^{***}$ $(.017)$ & $-0.458^{***}$ $(0.067)$ \\[+0.6cm]\hline
RQ1b & $\delta_{2}$ & $-.091^{***}$ (-.020) & $-0.210^{**}$ (0.039)\\[+0.6cm]\end{tabular}\\ \hline
\parbox{6.5cm}{$$\begin{gathered} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \\ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \\ \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{gathered}$$} &\begin{tabular}{@{}P{2.7 cm}P{2.15cm}|P{2 cm}|P{2 cm}@{}|} RQ2 & $\delta_{1}$ & $-.020$ $(.014)$
& $0.039$ $(0.055)$ \\[+0.6cm]\hline
RQ2 & $\delta_{2}$ & $.023^{\dagger}$ $(.014)$ & $0.209^{***}$ $(0.053)$ \\[+0.6cm]\end{tabular}\\ \hline
\end{tabular}
\caption{Caption}
\label{table2}
\end{table}
\noindent\textit{Note:} Unstandardized coefficients with corrected standard errors in parentheses.\\
$^{\dagger}$  p < .10, $^{*}$ p < .05, $^{**}$ p < .01, $^{***}$ p <  .001.
\clearpage

\end{document}


With use of the packages \makecell (for multi line column headers), tabularx (for X column type), threeparttablex (for \notes and \tnote in table and at end of table), siunitx (for S column type in last two columns), \mathtools (for multline math environment) and ˙nccmath(for\medmath which reduce size of equation):

\documentclass[12pt]{extarticle}
%\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\usepackage[T1]{fontenc}
\usepackage{mathtools, nccmath}
\usepackage{array, booktabs, makecell, multirow, tabularx}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}

\begin{document}

\begin{table}[htbp]
\centering
\sisetup{input-symbols={( )},
table-space-text-post={$^{***}$},
table-format=-1.3
}
\begin{ThreePartTable}
\begin{tabularx}{\linewidth}{@{} X c >{$}c<{$} S S @{}}
\toprule
\\
\cmidrule{4-5}
\midrule
\multirow{4}{=}{
$$\medmath{\begin{multlined} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{multlined} }$$
}% end of multirow
& RQ1a  & \delta_1  & 0.094\tnote{***}  &  0.458\tnote{***} \\
&       &           & (0.017)           & (0.067)           \\
& RQ1b  & \delta_2  &  0.091\tnote{***} &  0.210\tnote{**}  \\
&       &           & (0.020)           & (0.039)           \\
\midrule
\multirow{4}{=}{
$$\medmath{\begin{multlined} \mathrm{Y}=\beta_{0}+\beta_{1} \text{Income}+ \beta_{2}(\text{GrossSalary - Housing}) + \\ \beta_{3}(\text{Dearness - Extra }) + \delta_{1} \text{Housing}+\delta_{2} \text{Extra} \end{multlined} }$$
}% end of multirow
& RQ2a  & \delta_1  & 0.020             &  0.039            \\
&       &           & (0.014)           & (0.055)           \\
& RQ2b  & \delta_2  &  0.023\tnote{$\dagger$}
&  0.209\tnote{***} \\
&       &           & (0.014)           & (0.053)           \\
\bottomrule
\end{tabularx}
\begin{tablenotes}[flushleft, para]\footnotesize\raggedright
\note{Unstandardized coefficients with corrected standard errors in parentheses.}\\
\item[$\dagger$]  $p <0.10$,
\item[*]    $p <0.05$,
\item[**]   $p <0.01$,
\item[***]  $p <0.001$.
\end{tablenotes}
\end{ThreePartTable}
\end{table}
\end{document}


I would use a tabularx environment, align the numbers in the final two columns on their decimal markers, get rid of all vertical rules, and squeeze the final four columns as much as possible, all in order to set aside as much available width as possible for the first column. That way, one can just fit two-line aligned environments in the first columns.

Oh, and I would not use equation numbers.

\documentclass[a4paper,12pt]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[total={7in, 9in}]{geometry}

\usepackage{amsmath,booktabs,tabularx,ragged2e}
\usepackage{multirow,dcolumn}
\usepackage[stable]{footmisc}
\usepackage[justification=centering,
skip=0.333\baselineskip]{caption}

\usepackage{setspace}
\onehalfspacing

\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcolumntype{C}{>{\Centering\arraybackslash}X}

\newcolumntype{P}[1]{>{\Centering\arraybackslash}p{#1}}
\newcommand\mC[1]{\multicolumn{1}{P{\mylenb}@{}}{#1}}

\newlength\mylena
\settowidth\mylena{\textbf{Research}}
\newlength\mylenb
\settowidth\mylenb{\textbf{Response}}

\newcommand\mybox[1]{\parbox{\hsize}{\raggedright#1}}

\begin{document}

\begin{table}[htbp]

\begin{tabularx}{\textwidth}{@{} C P{\mylena} c d{2.5} d{2.5} @{}}
\toprule
\textbf{Model} & \textbf{Research Question} & \textbf{Coeff.} &
\mC{\textbf{Response A}} & \mC{\textbf{Response B}} \\
\midrule
\multirow{4}{*}{\mybox{%
\begin{aligned} Y&=\beta_{0} + \beta_{1} \mathrm{Income} + \beta_{2}(\mathrm{GrossSalary}-\mathrm{Housing}) \\ &\ + \beta_{3}(\mathrm{Dearness}-\mathrm{Extra}) + \delta_{1} \mathrm{Housing} + \delta_{2} \mathrm{Extra} \end{aligned}}}
& RQ1a & $\delta_{1}$ & -0.094^{***} & -0.458^{***} \\
& & & (0.017) & (0.067) \\
\cmidrule(l){2-5}
& RQ1b & $\delta_{2}$ & -0.091^{***} & -0.210^{**} \\
& & & (0.020) & (0.039) \\
\midrule
\multirow{4}{*}{\mybox{%
\begin{aligned} Y&=\beta_{0} + \beta_{1} \mathrm{Income} + \beta_{2}(\mathrm{GrossSalary}-\mathrm{Housing}) \\ &\ + \beta_{3}(\mathrm{Dearness}-\mathrm{Extra}) + \delta_{1} \mathrm{Housing} + \delta_{2} \mathrm{Extra} \end{aligned}}}
& RQ2 & $\delta_{1}$ & -0.020 & 0.039 \\
& & & (0.014) & (0.055) \\
\cmidrule(l){2-5}
& RQ2 & $\delta_{2}$ & 0.023^{\dagger} & 0.209^{***} \\
& & & (0.014) & (0.053) \\
\bottomrule
\multicolumn{5}{@{}l}{\small\textit{Note:} Unstandardized coefficients with corrected standard errors in parentheses.}\\
\multicolumn{5}{@{}l}{\small$^{\dagger}\ p < .10$, $^{*}\ p < .05$, $^{**} p < .01$, $^{***} p < .001$.}
\end{tabularx}

\caption{Caption}
\label{table2}
\end{table}

\end{document}


A variant of @Mico's solution, using a \multline environment, \useshortskipfrom nccmath and thead from makecell:

\documentclass[a4paper,12pt]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[total={7in, 9in}]{geometry}

\usepackage{amsmath, booktabs, tabularx, ragged2e}
\usepackage{nccmath}
\usepackage{multirow,dcolumn, makecell}
\usepackage[stable]{footmisc}
\usepackage[justification=centering, skip=6pt]{caption}
\usepackage{setspace}
\onehalfspacing

\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}

\begin{document}

\begin{table}[!htbp]
\setlength{\tabcolsep}{4pt}\centering
\begin{tabularx}{\linewidth}{@{}>{\useshortskip}Xc c d{2.5} d{2.5} @{}}
\toprule
\midrule
\multirow{2}{=}{%
\begin{multline}
Y=\beta_{0} + \beta_{1} \mathrm{Income} + \beta_{2}(\mathrm{GrossSalary}-\mathrm{Housing}) \\
+ \beta_{3}(\mathrm{Dearness}-\mathrm{Extra}) + \delta_{1} \mathrm{Housing} + \delta_{2} \mathrm{Extra}
\end{multline}}%
& RQ1a & $\delta_{1}$ & -0.094^{***} & -0.458^{***} \\
& & & (0.017) & (0.067) \\
\cmidrule(l){2-5}
& RQ1b & $\delta_{2}$ & -0.091^{***} & -0.210^{**} \\
& & & (0.020) & (0.039) \\
\midrule
\multirow{2}{=}{%
\begin{multline}
Y=\beta_{0} + \beta_{1} \mathrm{Income} + \beta_{2}(\mathrm{GrossSalary}-\mathrm{Housing}) \\
+ \beta_{3}(\mathrm{Dearness}-\mathrm{Extra}) + \delta_{1} \mathrm{Housing} + \delta_{2} \mathrm{Extra}
\end{multline}}
& RQ2 & $\delta_{1}$ & -0.020 & 0.039 \\
& & & (0.014) & (0.055) \\
\cmidrule(l){2-5}
& RQ2 & $\delta_{2}$ & 0.023^{\dagger} & 0.209^{***} \\
& & & (0.014) & (0.053) \\
\bottomrule
\multicolumn{5}{@{}l}{\small$^{\dagger}\ p < .10$,\enspace $^{*}\ p < .05$,\enspace $^{**} p < .01$,\enspace $^{***} p < .001$.}
`