Stargazer LaTeX 输出的回归表中的非法字符是什么?

Stargazer LaTeX 输出的回归表中的非法字符是什么?

我正在尝试使用 stargazer LaTeX 输出来生成 R 中的基本 OLS 回归表,但编译总是失败

\begin{tabular}{@{\extracolsep{5pt}}ld{.}{.}{-3}}

由于非法字符而导致行溢出。
代码如下:

\documentclass[12pt]{report}
\raggedright
\linespread{1.3}
\parskip=24pt

\usepackage{graphicx}

\usepackage{amsmath}

\usepackage[margin=1in]{geometry} % 1 inch margins all around

\usepackage[export]{adjustbox}

\usepackage{setspace}

\usepackage[utf8]{inputenc}

\begin{document}   

Question 1\par
\includegraphics{unit2q1_scatterplot.png}

Question 2\par
\begin{table}[!htbp] \centering 
  \caption{OLS Regression Results} 
  \label{}
\begin{tabular}{@{\extracolsep{5pt}}ld{.}{.}{-3}}
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & \multicolumn{1}{c}{Gun Regulations} \\ 
\hline \\[-1.8ex] 
 State Population (Hund Thou) & 0.070^{**} \\ 
  & (0.028) \\ 
  Constant & 20.194^{***} \\ 
  & (2.539) \\ 
 \hline \\[-1.8ex] 
Observations & \multicolumn{1}{c}{50} \\ 
R$^{2}$ & \multicolumn{1}{c}{0.116} \\ 
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.098} \\ 
Residual Std. Error & \multicolumn{1}{c}{13.286 (df = 48)} \\ 
F Statistic & \multicolumn{1}{c}{6.298$^{**}$ (df = 1; 48)} \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

\end{document}

谁能告诉我哪个字符是非法的以及为什么?

答案1

d{.}{.}{-3}

不是定义的列类型。也许您打算使用包dcolumn(但使用Dnot d

答案2

除了加载dcolumn包、发出指令\newcolumntype{d}[1]{D{.}{.}{#1}}和定义表格结构之外

\begin{tabular}{ld{2.5}}

你也应该努力让你的读者更容易吸收内容表格材料。以下代码和屏幕截图提供了一些建议:

在此处输入图片描述

\documentclass[12pt]{report}
\parskip=24pt
\usepackage{setspace}
\setstretch{1.3} % don't use the low-level '\linespread' macro directly

\usepackage[document]{ragged2e}
\usepackage{amsmath,dcolumn,booktabs}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage[margin=1in]{geometry} % 1" margins all around
\usepackage[export]{adjustbox}
\usepackage[utf8]{inputenc}

\begin{document}   

Question 2

\begin{table}[!htbp] 
\centering 
\caption{OLS Regression Results}  \label{}
Dependent variable: Gun Regulations

(Standard errors in parentheses)

\smallskip
\begin{tabular}{@{} l d{2.5} @{}}
\toprule
State Population (Hund Thou) & 0.070^{**} \\ 
         & (0.028) \\ 
Constant & 20.194^{***} \\ 
         & (2.539) \\ 
\midrule
Observations    & \multicolumn{1}{c}{50} \\ 
R\textsuperscript{2}           & 0.116   \\ 
Adjusted R\textsuperscript{2}  & 0.098   \\ 
Residual Std.\ Error (df = 48) & 13.286  \\ 
F Statistic (df = 1;48)        & 6.298^{**}\\ 
\midrule[\heavyrulewidth]
\multicolumn{2}{@{}l}{\textit{Note:} $^{*}\ p<0.1$; $^{**}\ p<0.05$; $^{***}\ p<0.01$} \\ 
\end{tabular} 
\end{table} 

\end{document}

相关内容