我为下表创建了一个代码。我的问题是,带有的列Var(\alpha^m)/Var(\alpha)
扰乱了表格第二部分“总变异百分比解释者:”的布局
你知道该如何解决这个问题吗?
\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{lscape}
\begin{document}
\begin{longtable}[c]{lccccccc}
\caption{Variability of Asset Demands}
\label{my-label}\\
\toprule
\multicolumn{1}{c}{\textbf{$~\gamma =5, \psi = 1, \rho =0.92^{1/4} $}} \\
\endfirsthead
%
\endhead
\toprule
&\multicolumn{1}{c}{\textbf{Var($\alpha^m$)/Var($\alpha$)(\%)}} &\multicolumn{1}{c}{\textbf{Var($\alpha^h$)/Var($\alpha$)(\%)}}
&\multicolumn{1}{c}{\textbf{Cov($\alpha^m$,$\alpha^h$)/Var($\alpha$)(\%)}}\\
%
\toprule
~~Stock & 71.33 & 71.33 & 71.33 \\
~~Bond & 71.33 & 71.33 & 71.33 \\
\toprule
\multicolumn{7}{l}{Percentage of Total Variation Explained By:} \\
\\
~~Stock \\
&&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
&$rtb_t$ &0.0254 & 0.0045 & -0.0037 & 0.0710 & 0.0425 & 0.0014\\
&$xr_t$ && 0.0055 & -0.0012 & 0.0142 & 0.0130 & 0.0005 \\
&$xb_t$ && & 0.0009 & -0.0116 & -0.0078 & -0.0002\\
&$y_t$ & && & 0.2177 & 0.1336 & 0.0041 \\
&$(d-p)_t$ && & & & 0.2374 & -0.0042\\
&$spr_t$ &&&&&&0.0008 \\
~~Bond \\
&&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
&$rtb_t$ & 0.0143 & 0.0088 & 0.0073 & 0.1078 & -0.0147 & -0.0148\\
&$xr_t$ &&0.0370 & 0.0079 & 0.0748 & -0.0156 & -0.0188\\
&$xb_t$ && &0.0062 & 0.0614 & -0.0095 & -0.0058\\
&$y_t$ & && & 0.8936 & -0.1250 & -0.1207\\
&$(d-p)_t$ && & & & 0.0507 & -0.0278\\
&$spr_t$ &&&&&&0.1679 \\
\bottomrule
\end{longtable}
\end{document}
答案1
您的表格实际上由两个单独的子表组成,它们之间的连接并不紧密(如果有的话)。如果您想保留单一longtable
设置,我建议您使用两个(逻辑)列来显示上部的数字信息。我还建议将下部的数字与各自的小数点对齐。哦,使用\bm
,而不是\textbf
,以粗体显示数学材料。
最后的评论:我不清楚你为什么要longtable
为这个材料使用环境。在一个环境中嵌套几个tabular
环境table
似乎更简单。
\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs,amsmath,bm,siunitx}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\begin{document}
\setlength\tabcolsep{4.5pt}
\begin{longtable}{@{} c *{6}{S[table-format=-1.4]} @{}}
\caption{Variability of Asset Demands}
\label{my-label}\\
\toprule
\multicolumn{7}{@{}l}{$\bm{\gamma =5,\ \psi = 1,\ \rho =0.92^{1/4} }$} \\
\midrule
\endfirsthead
\toprule
\endhead
\bottomrule
\endlastfoot
&\multicolumn{2}{c}{$\bm{\Var(\alpha^m)/\Var(\alpha)}$}
&\multicolumn{2}{c}{$\bm{\Var(\alpha^h)/\Var(\alpha)}$}
&\multicolumn{2}{c@{}}{$\bm{\Cov(\alpha^m,\alpha^h)/\Var(\alpha)}$} \\[0.5ex]
& \multicolumn{2}{c}{(\%)}
& \multicolumn{2}{c}{(\%)}
& \multicolumn{2}{c@{}}{(\%)} \\
%
\midrule
Stock & \multicolumn{2}{c}{71.33}
& \multicolumn{2}{c}{71.33}
& \multicolumn{2}{c@{}}{71.33} \\
Bond & \multicolumn{2}{c}{71.33}
& \multicolumn{2}{c}{71.33}
& \multicolumn{2}{c@{}}{71.33} \\
\midrule
\addlinespace
\multicolumn{7}{@{}l}{Percentage of Total Variation Explained By:} \\[1ex]
Stock \\
&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
{$rtb_t$} &0.0254 & 0.0045 & -0.0037 & 0.0710 & 0.0425 & 0.0014\\
{$xr_t$} && 0.0055 & -0.0012 & 0.0142 & 0.0130 & 0.0005 \\
{$xb_t$} && & 0.0009 & -0.0116 & -0.0078 & -0.0002\\
{$y_t$} & && & 0.2177 & 0.1336 & 0.0041 \\
{$(d-p)_t$} && & & & 0.2374 & -0.0042\\
{$spr_t$} &&&&&&0.0008 \\[3ex]
Bond \\
&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
{$rtb_t$} & 0.0143 & 0.0088 & 0.0073 & 0.1078 & -0.0147 & -0.0148\\
{$xr_t$} &&0.0370 & 0.0079 & 0.0748 & -0.0156 & -0.0188\\
{$xb_t$} && &0.0062 & 0.0614 & -0.0095 & -0.0058\\
{$y_t$} & && & 0.8936 & -0.1250 & -0.1207\\
{$(d-p)_t$} && & & & 0.0507 & -0.0278\\
{$spr_t$} &&&&&&0.1679 \\
\end{longtable}
\end{document}
答案2
这里的方法略有不同,使用两个单独的tabular*
环境来表示上部和下部。两个tabular*
环境共享相同的宽度 ( \textwidth
),以确保水平规则的宽度相等(建议Mico 在评论中)。为了使数字相对于小数点分隔符对齐,我使用了包S
中的类型列siunitx
。我还添加了threeparttable
环境和tablenotes
以允许在表格下方添加注释,如问题中的图片所示。为了确保表格适合文本宽度,我稍微减小了tabcolsep
。
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{bm}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\begin{document}
\begin{table}
\caption{Variability of Asset Demands}
\label{my-label}
\setlength{\tabcolsep}{4pt}
\begin{threeparttable}
% \begin{tabular}{@{}l@{}}
\begin{tabular*}{\textwidth}{l*3{S[table-format=2.2]}}
\toprule
\multicolumn{4}{c}{$\bm{\gamma =5,\ \psi = 1,\ \rho =0.92^{1/4} }$}\\
\midrule
&{$\bm{\Var(\alpha^m)/\Var(\alpha)}$}& {$\bm{\Var(\alpha^h)/\Var(\alpha)}$} &{$\bm{\Cov(\alpha^m,\alpha^h)/\Var(\alpha)}$}\\
& {(\%)} & {(\%)} & {(\%)} \\
\cmidrule(rl){2-2} \cmidrule(rl){3-3} \cmidrule(rl){4-4}
Stock & 71.33 & 71.33 & 71.33\\
Bond & 71.33 & 71.33 & 71.33\\
\end{tabular*}
\begin{tabular*}{\textwidth}{@{\hspace{5ex}}r*2{S[table-format=1.4]}*4{S[table-format=-1.4]}}
\midrule
\multicolumn{7}{c}{Percentage of Total Variation Explained By:}\\
\multicolumn{1}{l}{Stock} \\
&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
$rtb_t$ &0.0254 & 0.0045 & -0.0037 & 0.0710 & 0.0425 & 0.0014\\
$xr_t$ && 0.0055 & -0.0012 & 0.0142 & 0.0130 & 0.0005 \\
$xb_t$ && & 0.0009 & -0.0116 & -0.0078 & -0.0002\\
$y_t$ & && & 0.2177 & 0.1336 & 0.0041 \\
$(d-p)_t$ && & & & 0.2374 & -0.0042\\
$spr_t$ &&&&&&0.0008 \\
\addlinespace
\multicolumn{1}{@{\hspace{\tabcolsep}}l}{Bond} \\
&{$rtb_t$} & {$xr_t$ } & {$xb_t$} &{$y_t$} & {$(d-p)_t$} & {$spr_t$} \\
$rtb_t$ & 0.0143 & 0.0088 & 0.0073 & 0.1078 & -0.0147 & -0.0148\\
$xr_t$ &&0.0370 & 0.0079 & 0.0748 & -0.0156 & -0.0188\\
$xb_t$ && &0.0062 & 0.0614 & -0.0095 & -0.0058\\
$y_t$ & && & 0.8936 & -0.1250 & -0.1207\\
$(d-p)_t$ && & & & 0.0507 & -0.0278\\
$spr_t$ &&&&&&0.1679 \\
\bottomrule
\end{tabular*}
% \end{tabular}
\begin{tablenotes}
\item[] \textbf{Note:} Here can be the table notes
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}