需要帮助对长桌进行外观改造

需要帮助对长桌进行外观改造

我需要一些有关长表(代码如下)的帮助。我有几件事想做,但一直没能做到。

1)我希望灰色背景以与该表类似的方式覆盖表格:

在此处输入图片描述

2)我希望表格的宽度占据整个页面,并与标题和页脚完美对齐(与(1)中的示例相同)

3)我不想mdframed在阴影边缘显示黑线。

4) 我希望每列的非小数元素与小数元素对齐。我不确定如何使用 dcolumn 包实现这一点。现在,我使用了一种糟糕的方法,在\multicolumn文本之前或之后添加灰色(即,出于实际目的不可见)元素,将其推到中心。

请注意,我不能使用\rowcolorfrom colortblwith \multicolumn

谢谢你的帮助 :)

PS:我对 LaTeX 还很陌生,这不仅仅是因为懒惰!

\documentclass[a4paper,11pt]{article}
\usepackage{color,amsmath,amsfonts,amssymb}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{rotating}
\usepackage{colortbl}
\usepackage{booktabs,dcolumn,caption}
\usepackage{expdlist}  %expanded list environment
\usepackage{pdflscape} %landscape single pages
\usepackage{longtable} %multipage table
\usepackage{xcolor, mdframed}

\captionsetup{labelsep=newline,singlelinecheck=false} % optional
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\renewcommand{\ast}{{}^{\textstyle *}} % for raised "asterisks"

\oddsidemargin 0.5cm %
\evensidemargin 0.5cm %
\textwidth 15cm %
\topmargin  -0.2in  %
\textheight 23.5cm %
\headheight 15pt %


\doublerulesep2pt

\begin{document}
\renewcommand{\baselinestretch}{1.1}

\fontsize{11}{16pt} \selectfont
\definecolor{Gray}{gray}{0.9}


\begin{landscape}
\footnotesize
\begin{mdframed}[backgroundcolor=Gray]
\begin{longtable}{@{}l@{\extracolsep{\fill}}d{4}d{4}d{4}d{4}d{4}d{4}d{4}d{4}d{4}@{}}
\caption{HEADING} \\
%\begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}d{4}d{4}d{4}d{4}d{4}d{4}d{4}d{4}d{4}@{}}
\toprule
& \multicolumn{3}{c}{Category 1} & \multicolumn{3}{c}{Category 2} & \multicolumn{3}{c}{Category 3} \\
& \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{PWLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS}  \\
\midrule
\endfirsthead
\caption[]{\emph{(continued)}} \\
\toprule
& \multicolumn{3}{c}{Category 1} & \multicolumn{3}{c}{Category 2} & \multicolumn{3}{c}{Category 3} \\
& \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{PWLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS} & \multicolumn{1}{c}{OLS}  \\
\midrule
\endhead



\multicolumn{4}{l}{\emph{Heading1}} & & &  & & & \\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 &     -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) &     (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 &     -0.002 & 0.465\ast \ast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) &     (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 &     0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) &     (0.132) \\
Var4\textsuperscript{c} & -0.333\ast \ast & -0.333\ast \ast & 15.347\ast \ast &     -0.179\ast \ast & -0.180\ast \ast & -8.593\ast \ast & -0.050 & -0.013 & -3.678\ast \ast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) &     (1.049) \\
    Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\ast \ast & -0.066\ast \ast &     -0.035\ast & 2.166\ast \ast & -0.161\ast \ast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) &     (0.451) \\
Var6 & \multicolumn{1}{c}{Yes\textsuperscript{**}} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} \\
R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
& & & & & & & & & \\

\multicolumn{4}{l}{\emph{Heading2}} & & &  & & & \\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 &     -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) &     (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 & -0.002 & 0.465\ast \ast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) & (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 & 0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) & (0.132) \\
Var4\textsuperscript{c} & -0.333\ast \ast & -0.333\ast \ast & 15.347\ast \ast & -0.179\ast \ast & -0.180\ast \ast & -8.593\ast \ast & -0.050 & -0.013 & -3.678\ast \ast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) & (1.049) \\
Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\ast \ast & -0.066\ast \ast &     -0.035\ast & 2.166\ast \ast & -0.161\ast \ast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) & (0.451) \\
    Var6 & \multicolumn{1}{c}{Yes\textsuperscript{**}} & Yes^{**} & Yes^{**} &     Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} \\
    R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
& & & & & & & & & \\

\pagebreak

\multicolumn{4}{l}{\emph{Heading3}} & & &  & & & \\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 & -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) &     (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 & -0.002 & 0.465\ast \ast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) & (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 & 0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) & (0.132) \\
Var4\textsuperscript{c} & -0.333\ast \ast & -0.333\ast \ast & 15.347\ast \ast & -0.179\ast \ast & -0.180\ast \ast & -8.593\ast \ast & -0.050 & -0.013 & -3.678\ast \ast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) & (1.049) \\
Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\ast \ast & -0.066\ast \ast & -0.035\ast & 2.166\ast \ast & -0.161\ast \ast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) & (0.451) \\
    Var6 & \multicolumn{1}{c}{Yes\textsuperscript{**}} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} & Yes^{**} \\
    R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
& & & & & & & & & \\
No. 1 & \multicolumn{1}{c}{219\textcolor{Gray}{ss}} & \multicolumn{1}{c}{219} &     \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} &     \multicolumn{1}{c}{219} & \multicolumn{1}{c}{445} & \multicolumn{1}{c}{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
No. 2 & \multicolumn{1}{c}{219\textcolor{Gray}{ss}} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{445} & \multicolumn{1}{c}{445} &     \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
No. 3 & \multicolumn{1}{c}{219\textcolor{Gray}{ss}} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{445} & \multicolumn{1}{c}{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
days 1 & \multicolumn{1}{c}{219\textcolor{Gray}{ss}} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{445} & \multicolumn{1}{c}{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
days 2 & \multicolumn{1}{c}{219\textcolor{Gray}{ss}} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{219} & \multicolumn{1}{c}{445} & \multicolumn{1}{c}{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
\midrule[\heavyrulewidth]
\end{longtable}
\vspace{0.12cm}
\end{mdframed}

{Dependent variables have been scaled by a factor of 10. Standard errors in parentheses. *Significant at 5\%; **Significant at 1\%.
\begin{description}\compact{
        \item[\small \textsuperscript{a}] Description 1.
    \item[\small \textsuperscript{b}] Description 1.
    \item[\small \textsuperscript{c}] Description 1.
        \item[\small \textsuperscript{d}] Description 1. }
\end{description} }
\end{landscape}



\end{document}

答案1

您有不少问题!我重新编写了您的代码以解决您的所有问题,并修复了一些其他问题。我似乎无法解决的唯一问题是longtable和之间的奇怪交互mdframed:如果mdframed在环境周围放置环境,并且为前一个包启用了诸如(或,比如)longtable之类的选项,则 longtable 的各种元素(例如 endhead、endfoot 和 endlastfoot)会神秘消失。也许其他人可以建议怎么做?目前,与 mdframed 相关的命令已被注释掉。hidealllines=truelinecolor=white

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage[english]{babel}
\usepackage{natbib}
\usepackage{pdflscape,booktabs,dcolumn,caption}
\usepackage{expdlist}  %expanded list environment

\usepackage{longtable} %multipage table
\setlength\LTleft{0pt}
\setlength\LTright{0pt}

\usepackage[table]{xcolor} 
\definecolor{Gray}{gray}{0.9}
\usepackage{mdframed}

\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\setstretch{1}

\captionsetup{labelsep=newline,singlelinecheck=false} % optional
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type

\renewcommand{\ast}{\ensuremath{{}^{\textstyle *}}} % for raised "asterisks"
\newcommand{\aast}{\ensuremath{{}^{\textstyle **}}}

\newcommand{\C}[1]{\multicolumn{1}{c}{#1}} % abbreviations 
\newcommand\Y{\C{Yes\aast}}


\begin{document}

\begin{landscape}
%%\begin{mdframed}[backgroundcolor=Gray,hidealllines=true]
\noindent
\begin{longtable}{@{} l @{\extracolsep{\fill}} *{9}{d{5}} @{}}
\caption{HEADING} \\
\toprule
& \multicolumn{3}{c}{Category 1} 
& \multicolumn{3}{c}{Category 2} 
& \multicolumn{3}{c}{Category 3} \\
\cmidrule(r){2-4} \cmidrule(r){5-7} \cmidrule(l){8-10}
& \C{OLS} & \C{OLS} & \C{OLS} 
& \C{OLS} & \C{OLS} & \C{PWLS} 
& \C{OLS} & \C{OLS} & \C{OLS} \\
\midrule
\endfirsthead
\multicolumn{5}{@{}l}{\emph{(continued)}} \\
\toprule
& \multicolumn{3}{c}{Category 1} 
& \multicolumn{3}{c}{Category 2} 
& \multicolumn{3}{c}{Category 3} \\
\cmidrule(r){2-4} \cmidrule(r){5-7} \cmidrule(l){8-10}
& \C{OLS} & \C{OLS} & \C{OLS} 
& \C{OLS} & \C{OLS} & \C{PWLS} 
& \C{OLS} & \C{OLS} & \C{OLS} \\
\midrule
\endhead
\midrule[\heavyrulewidth]
\multicolumn{10}{r@{}}{\emph{(continued)}}
\endfoot
\bottomrule
\endlastfoot
\multicolumn{4}{@{}l}{\emph{Heading 1}} \\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 & -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) & (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 & -0.002 & 0.465\aast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) & (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 & 0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) & (0.132) \\
Var4\textsuperscript{c} & -0.333\aast & -0.333\aast & 15.347\aast & -0.179\aast & -0.180\aast & -8.593\aast & -0.050 & -0.013 & -3.678\aast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) & (1.049) \\
Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\aast & -0.066\aast & -0.035\ast & 2.166\aast & -0.161\aast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) & (0.451) \\
Var6 & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y \\
R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
\\
\multicolumn{4}{@{}l}{\emph{Heading2}} \\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 & -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) & (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 & -0.002 & 0.465\aast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) & (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 & 0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) & (0.132) \\
Var4\textsuperscript{c} & -0.333\aast & -0.333\aast & 15.347\aast & -0.179\aast & -0.180\aast & -8.593\aast & -0.050 & -0.013 & -3.678\aast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) & (1.049) \\
Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\aast & -0.066\aast & -0.035\ast & 2.166\aast & -0.161\aast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) & (0.451) \\
Var6 & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y \\
R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
\\
\multicolumn{4}{@{}l}{\emph{Heading3}}\\
Var1 & -0.086 & -0.082 & -4.525 & -0.028 & -0.022 & 2.441 & -0.092 & -0.099 & -3.837\ast \\
& (0.107) & (0.110) & (3.948) & (0.087) & (0.091) & (4.346) & (0.076) & (0.070) & (1.505) \\
Var2\textsuperscript{a}  & 0.012 & 0.012 & -0.007 & 0.004 & 0.003 & 0.046 & 0.000 & -0.002 & 0.465\aast \\
& (0.009) & (0.009) & (0.319) & (0.007) & (0.007) & (0.351) & (0.006) & (0.006) & (0.120) \\
Var3\textsuperscript{b} & -0.006 & -0.005 & 0.452 & 0.001 & 0.003 & -0.204 & 0.003 & 0.009 & -0.082 \\
& (0.007) & (0.007) & (0.247) & (0.005) & (0.006) & (0.272) & (0.007) & (0.006) & (0.132) \\
Var4\textsuperscript{c} & -0.333\aast & -0.333\aast & 15.347\aast & -0.179\aast & -0.180\aast & -8.593\aast & -0.050 & -0.013 & -3.678\aast \\
& (0.078) & (0.080) & (2.87) & (0.063) & (0.066) & (3.160) & (0.053) & (0.049) & (1.049) \\
Var5\textsuperscript{d} & -0.037 & -0.010 & -2.073\aast & -0.066\aast & -0.035\ast & 2.166\aast & -0.161\aast & -0.043\ast & -0.834 \\
& (0.021) & (0.021) & (0.761) & (0.017) & (0.017) & (0.838) & (0.023) & (0.021) & (0.451) \\
Var6 & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y & \Y \\
R-squared & 0.151 & 0.146 & 0.191 & 0.111 & 0.07 & 0.086 & 0.151 & 0.013 & 0.187 \\
\\
No. 1 & \C{219\textcolor{Gray}{ss}} & \C{219} & \C{219} & \C{219} & \C{219} & \C{219} & \C{445} & \C{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
No. 2 & \C{219\textcolor{Gray}{ss}} & \C{219} & \C{219} & \C{219} & \C{219} & \C{219} & \C{445} & \C{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
No. 3 & \C{219\textcolor{Gray}{ss}} & \C{219} & \C{219} & \C{219} & \C{219} & \C{219} & \C{445} & \C{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
days 1 & \C{219\textcolor{Gray}{ss}} & \C{219} & \C{219} & \C{219} & \C{219} & \C{219} & \C{445} & \C{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
days 2 & \C{219\textcolor{Gray}{ss}} & \C{219} & \C{219} & \C{219} & \C{219} & \C{219} & \C{445} & \C{445} & \multicolumn{1}{r}{445\textcolor{Gray}{s}} \\
\end{longtable}
\noindent
Dependent variables have been scaled by a factor of 10. Standard errors in parentheses. \ast~Significant at 5\%; \aast~Significant at 1\%.
\begin{description}\compact{
    \item[\small \textsuperscript{a}] Description 1.
    \item[\small \textsuperscript{b}] Description 1.
    \item[\small \textsuperscript{c}] Description 1.
    \item[\small \textsuperscript{d}] Description 1. }
\end{description} 
%%\end{mdframed}
\end{landscape}
\end{document}

答案2

1)我希望灰色背景以类似于此表的方式覆盖表格:http://i50.tinypic.com/2hz4ao0.png

2)我希望表格的宽度占据整个页面,并与标题和页脚完美对齐(与(1)中的示例相同:http://i50.tinypic.com/2hz4ao0.png)

添加

\setlength{\LTleft}{0pt}
\setlength{\LTright}{0pt}

要去除 LT 边距(您已经有@{}和列间填充胶。

3) 我不希望 mdframed 在阴影边缘显示黑线。

\begin{mdframed}[backgroundcolor=Gray, hidealllines=true]

将删除行

4) 我希望每列的非十进制元素与十进制元素对齐。我不确定如何使用 dcolumn 包实现这一点。现在,我使用 \multicolumn 和灰色(即,出于实际目的不可见)元素将其推到文本之前或之后,这是一种糟糕的破解方法。

不太确定你想要什么样的对齐方式,但对于非数字输入来说,使用\multicolumn{1}并不是一种黑客攻击,而是一个设计精妙的界面dcolumn:-)

请注意,我不能将 colortbl 中的 \rowcolor 与 \multicolumn 一起使用。

如果您的意思和我的想法一致,那么您的意思是 colortbl 2012 版本中删除了一个“功能”,所以它现在应该可以工作了。

相关内容