4

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{equation}
    \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}
\end{equation}

\begin{equation}
    \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}
\end{equation}
\clearpage

\end{document}

And it looks like: enter image description here

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:

enter image description here

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{equation}
    \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}
\end{equation}} & 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{equation}
    \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}
\end{equation}} & 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

enter image description here

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.

4
  • 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? – leandriis Nov 7 '19 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. – wrahool Nov 7 '19 at 19:58
  • @wrahool ... in my solution add bigger spaces (in the code \\[+0.6cm])... You have to manually find the appropriate added height. – koleygr Nov 7 '19 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 '19 at 6:36
4

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{equation}
    \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}
\end{equation}} &\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{equation}
    \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}
\end{equation}} &\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}

enter image description here

4

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):

enter image description here

\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}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\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
    &   &   &   \multicolumn{2}{c}{\thead{Response}}
                                                        \\
    \cmidrule{4-5}
\thead{Model}
    &   \multirow{-2}{*}{\thead[b]{Research\\ Question}}
        &   \thead{\text{Coef.}}
            &   {\thead{A}}
                &   {\thead{B}}                     \\
    \midrule
\multirow{4}{=}{
\begin{equation}\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{equation}
}% end of multirow
    & RQ1a  & \delta_1  & 0.094\tnote{***}  &  0.458\tnote{***} \\ 
    &       &           & (0.017)           & (0.067)           \\
    \addlinespace
    & RQ1b  & \delta_2  &  0.091\tnote{***} &  0.210\tnote{**}  \\
    &       &           & (0.020)           & (0.039)           \\
    \midrule
\multirow{4}{=}{
\begin{equation}\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{equation}
}% end of multirow
    & RQ2a  & \delta_1  & 0.020             &  0.039            \\
    &       &           & (0.014)           & (0.055)           \\
    \addlinespace
    & 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}             
3

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.

enter image description here

\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
\addlinespace
\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}
0

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}
\renewcommand{\theadfont}{\small\bfseries}
\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
\thead{Model} & \thead{Research\\ Question} & \thead{Coeff.} &
\multicolumn{1}{c}{\thead{Response\\ A}} & \multicolumn{1}{c}{\thead{Response\\ B}} \\
\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
\addlinespace[0.6ex]
\multicolumn{5}{@{}l}{\small\textit{Note:} Unstandardized coefficients with corrected standard errors in parentheses.}\\
\multicolumn{5}{@{}l}{\small$^{\dagger}\ p < .10$,\enspace $^{*}\ p < .05$,\enspace $^{**} p < .01$,\enspace $^{***} p < .001$.}
\end{tabularx}
\caption{Caption}
\label{table2}
\end{table}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.