使用 vtable 包创建的表没有出现

使用 vtable 包创建的表没有出现

我以前用过 stargazer,但这个包 (vtable) 更适合按组进行汇总。我选择“latex”作为输出,并生成了下表。但是,我的 overleaf 文章无法识别该表,因为出现了几个错误。我做错了什么?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphics}
\usepackage[export]{adjustbox}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{array}

\begin{document}

\begin{table}[!htbp] \centering 
 \renewcommand*{\arraystretch}{1.1} 
\resizebox{\textwidth}{!}{ 

\caption{Summary Statistics}

\begin{tabular}{lrrrrrrr}
\hline
\hline
Variable & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Pctl. 25} & \multicolumn{1}{c}{Pctl. 75} & \multicolumn{1}{c}{Max} \\ 
\hline
\multicolumn{8}{c}{aliado: 0} \\ 
ano & 36423 & 2008.478 & 4.945 & 2000 & 2005 & 2012 & 2018 \\ 
orientacao & 36423 &  &  &  &  &  &  \\ 
... Centro & 8337 & 22.9\% &  &  &  &  &  \\ 
... Direita & 14578 & 40\% &  &  &  &  &  \\ 
... Esquerda & 13508 & 37.1\% &  &  &  &  &  \\ 
code & 36423 & 3216561.645 & 971270.128 & 1100023 & 2506103 & 4109302 & 5222302 \\ 
code\_6 & 36423 & 321655.708 & 97127.013 & 110002 & 250610 & 410930 & 522230 \\ 
servico & 36423 &  &  &  &  &  &  \\ 
... Água & 26633 & 73.1\% &  &  &  &  &  \\ 
... Água e Esgoto & 9782 & 26.9\% &  &  &  &  &  \\ 
... Esgoto & 8 & 0\% &  &  &  &  &  \\ 
paralisacao\_duracao & 9470 & 29.03 & 220.606 & 0 & 6.67 & 14 & 6668.44 \\ 
intermitencia\_duracao & 5296 & 66.535 & 595.074 & 0 & 3.2 & 13 & 31542.86 \\ 
cloro\_residual & 28060 & 4.887 & 14.346 & 0 & 0 & 2.24 & 100 \\ 
turbidez & 28145 & 7.053 & 17.494 & 0 & 0 & 4.12 & 100 \\ 
reparos\_esgotos\_duracao & 3956 & 12.598 & 41.359 & 0 & 1.85 & 11 & 1213.02 \\ 
servico\_duracao & 15046 & 53.879 & 289.9 & 0 & 1.03 & 58.373 & 22861.5 \\ 
 &  &  &  &  &  &  &  \\ 
\multicolumn{8}{c}{aliado: 1} \\ 
ano & 7256 & 2007.959 & 4.923 & 2000 & 2004 & 2012 & 2018 \\ 
orientacao & 7256 &  &  &  &  &  &  \\ 
... Centro & 3300 & 45.5\% &  &  &  &  &  \\ 
... Direita & 314 & 4.3\% &  &  &  &  &  \\ 
... Esquerda & 3642 & 50.2\% &  &  &  &  &  \\ 
code & 7256 & 3185174.31 & 981385.162 & 1100049 & 2413557 & 4127304 & 5221700 \\ 
code\_6 & 7256 & 318516.978 & 98138.517 & 110004 & 241355 & 412730 & 522170 \\ 
servico & 7256 &  &  &  &  &  &  \\ 
... Água & 5809 & 80.1\% &  &  &  &  &  \\ 
... Água e Esgoto & 1443 & 19.9\% &  &  &  &  &  \\ 
... Esgoto & 4 & 0.1\% &  &  &  &  &  \\ 
paralisacao\_duracao & 1395 & 36.507 & 247.343 & 0 & 6 & 16 & 4568.29 \\ 
intermitencia\_duracao & 753 & 66.844 & 714.663 & 0 & 3 & 12 & 18360 \\ 
cloro\_residual & 5144 & 5.345 & 14.739 & 0 & 0 & 2.872 & 100 \\ 
turbidez & 5120 & 8.025 & 17.778 & 0 & 0 & 6.005 & 100 \\ 
reparos\_esgotos\_duracao & 396 & 33.269 & 68.916 & 0 & 2 & 21.088 & 405.98 \\ 
servico\_duracao & 2516 & 66.857 & 396.499 & 0 & 1 & 49.752 & 14540.2\\ 
\hline
\hline
\end{tabular} %
}
\end{table} 

\end{document}

答案1

要消除错误消息,请将\caption命令放在 之外\resizebox。更好的方法是将\resizboxalltogether 删除,因为在表格上使用它只会导致整个文档的字体大小不一致。此外,您的表格已经与文本宽度一样宽,因此 \resizebox` 在这里没有任何效果。

在以下 MWE 中,我还用您已加载的包\hline中的行替换了命令。我还对您的序言做了一些注释更改:booktabs

在此处输入图片描述

\documentclass{article}
%\usepackage[utf8]{inputenc}% not needed any more in a recent installation
%\usepackage{graphics}% replaced with graphicx
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{amssymb}

%\usepackage{array}% already loaded by tabularx.
\usepackage{hyperref} % Should, with just a few exceptions, be the last package in your preamble

\begin{document}

\begin{table}[!htbp] 
\centering 
\caption{Summary Statistics}
\begin{tabular}{lrrrrrrr}
\toprule
Variable & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Pctl. 25} & \multicolumn{1}{c}{Pctl. 75} & \multicolumn{1}{c}{Max} \\ 
\midrule
\multicolumn{8}{c}{aliado: 0} \\ 
\midrule
ano & 36423 & 2008.478 & 4.945 & 2000 & 2005 & 2012 & 2018 \\ 
orientacao & 36423 &  &  &  &  &  &  \\ 
... Centro & 8337 & 22.9\% &  &  &  &  &  \\ 
... Direita & 14578 & 40\% &  &  &  &  &  \\ 
... Esquerda & 13508 & 37.1\% &  &  &  &  &  \\ 
code & 36423 & 3216561.645 & 971270.128 & 1100023 & 2506103 & 4109302 & 5222302 \\ 
code\_6 & 36423 & 321655.708 & 97127.013 & 110002 & 250610 & 410930 & 522230 \\ 
servico & 36423 &  &  &  &  &  &  \\ 
... Água & 26633 & 73.1\% &  &  &  &  &  \\ 
... Água e Esgoto & 9782 & 26.9\% &  &  &  &  &  \\ 
... Esgoto & 8 & 0\% &  &  &  &  &  \\ 
paralisacao\_duracao & 9470 & 29.03 & 220.606 & 0 & 6.67 & 14 & 6668.44 \\ 
intermitencia\_duracao & 5296 & 66.535 & 595.074 & 0 & 3.2 & 13 & 31542.86 \\ 
cloro\_residual & 28060 & 4.887 & 14.346 & 0 & 0 & 2.24 & 100 \\ 
turbidez & 28145 & 7.053 & 17.494 & 0 & 0 & 4.12 & 100 \\ 
reparos\_esgotos\_duracao & 3956 & 12.598 & 41.359 & 0 & 1.85 & 11 & 1213.02 \\ 
servico\_duracao & 15046 & 53.879 & 289.9 & 0 & 1.03 & 58.373 & 22861.5 \\ 
\midrule
\multicolumn{8}{c}{aliado: 1} \\ 
\midrule
ano & 7256 & 2007.959 & 4.923 & 2000 & 2004 & 2012 & 2018 \\ 
orientacao & 7256 &  &  &  &  &  &  \\ 
... Centro & 3300 & 45.5\% &  &  &  &  &  \\ 
... Direita & 314 & 4.3\% &  &  &  &  &  \\ 
... Esquerda & 3642 & 50.2\% &  &  &  &  &  \\ 
code & 7256 & 3185174.31 & 981385.162 & 1100049 & 2413557 & 4127304 & 5221700 \\ 
code\_6 & 7256 & 318516.978 & 98138.517 & 110004 & 241355 & 412730 & 522170 \\ 
servico & 7256 &  &  &  &  &  &  \\ 
... Água & 5809 & 80.1\% &  &  &  &  &  \\ 
... Água e Esgoto & 1443 & 19.9\% &  &  &  &  &  \\ 
... Esgoto & 4 & 0.1\% &  &  &  &  &  \\ 
paralisacao\_duracao & 1395 & 36.507 & 247.343 & 0 & 6 & 16 & 4568.29 \\ 
intermitencia\_duracao & 753 & 66.844 & 714.663 & 0 & 3 & 12 & 18360 \\ 
cloro\_residual & 5144 & 5.345 & 14.739 & 0 & 0 & 2.872 & 100 \\ 
turbidez & 5120 & 8.025 & 17.778 & 0 & 0 & 6.005 & 100 \\ 
reparos\_esgotos\_duracao & 396 & 33.269 & 68.916 & 0 & 2 & 21.088 & 405.98 \\ 
servico\_duracao & 2516 & 66.857 & 396.499 & 0 & 1 & 49.752 & 14540.2\\ 
\bottomrule
\end{tabular} %

\end{table} 

\end{document}

相关内容