![用表格单元格中的数据拟合大型方程](https://linux22.com/image/404190/%E7%94%A8%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E6%8B%9F%E5%90%88%E5%A4%A7%E5%9E%8B%E6%96%B9%E7%A8%8B.png)
我目前有一张表格和两个这样的方程式:
\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}
不过,我也希望在单元格中包含方程式(代替模型 1 和 2 这两个词)。
当我用整个方程式替换单词时,我的表格看起来很丑陋:
代码如下:
\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}
我想让行变宽以适合方程式。我该怎么做?
编辑:@koleygr 的答案对我来说不太适用。我明白了
一些列分隔符不完整,并且所有单元格值在所有边上的填充并不相同(看起来不一致)。
至于@Mico的回答,我给出的方程式是示例方程式。较长的方程式不适合单元格。
答案1
只是一个避免多行的想法:
\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}
答案2
使用包\makecell
(用于多行列标题)、tabularx
(用于X
列类型)、 threeparttablex
(用于表格中\notes
和\tnote
表格末尾)、siunitx
(用于S
最后两列的列类型)、\mathtools
(用于multline
数学环境)和˙nccmath (for
\medmath` 来减少方程的大小):
\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
我会使用tabularx
环境,将最后两列的数字与小数点对齐,删除所有垂直规则,并尽可能挤压最后四列,所有这些都是为了为第一列留出尽可能多的可用宽度。这样,就可以只是aligned
在第一列中适合两行环境。
哦,我会的不是使用方程编号。
\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}
答案4
@Mico 解决方案的一个变体,使用\multline
环境,\useshortskip
来自nccmath
和thead
来自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}