我正在使用 stargazer 包来生成一些回归表。但是,该表很长,我正在自定义 stargazer 的输出以对长表进行调整。序言如下:
\documentclass[12pt,a4paper,twoside]{article}
\usepackage[tc]{titlepic}
\usepackage{titlesec}
\usepackage[T1]{fontenc}
\usepackage{newtxtext}
\usepackage[latin9]{inputenc}
\usepackage[english]{babel}
\usepackage{tocbibind}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{mathptmx}
\usepackage{mathrsfs}
\DeclareMathOperator*{\Soperator}{\mathit{S}}
\usepackage{calrsfs}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=3cm,rmargin=3cm }
\usepackage{tabulary}
\usepackage[para]{threeparttable}
\usepackage{array,longtable,tabularx}
\usepackage{booktabs,ragged2e,ltxtable,pdflscape,filecontents}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}% <-- added
\usepackage{ltablex}% <-- added
\usepackage{siunitx}% <-- added
\usepackage[flushleft, online]{threeparttablex}
\usepackage{dcolumn}
\title{A Test Paper}
\date{}
\begin{document}
\maketitle{}
\begin{ThreePartTable}
\footnotesize
\setlength{\tabcolsep}{4.5pt}
\begin{TableNotes}[para]%
\footnotesize
\item[]This is ordinary least square.
\end{TableNotes}
\begin{longtable}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} }
\caption{OLS}
\label{tab1}\\
\insertTableNotes\\
\toprule
\midrule
{\bfseries{}} &{\bfseries(1)} & {\bfseries(2)} &{\bfseries(3)} & {\bfseries(4)} \\
\endfirsthead
\caption{-- continued from previous page}\\
\toprule
& {\bfseries(1)} & {\bfseries(2)} &{\bfseries(3)} & {\bfseries(4)}\\
\midrule
\endhead
\bottomrule
\addlinespace
\multicolumn{5}{r}{\footnotesize Continued on next page} \\
\endfoot
\addlinespace
\endlastfoot %
\midrule
treat1SEC & 0.083^{***} & 0.080^{***} & 0.071^{***} & 0.070^{***} \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
treat1CB & -0.002 & 0.007 & -0.001 & 0.002 \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
tfcSEC & -0.151^{***} & -0.157^{***} & -0.139^{***} & -0.126^{***} \\
& (0.017) & (0.017) & (0.023) & (0.022) \\
tfcCB & -0.006 & -0.028 & -0.011 & -0.012 \\
& (0.017) & (0.018) & (0.023) & (0.022) \\
Xtrwata & & -0.165^{***} & -0.162^{***} & 0.278^{***} \\
& & (0.045) & (0.045) & (0.068) \\
Xtllpr & & 2.825^{***} & 2.819^{***} & 4.304^{***} \\
& & (0.732) & (0.732) & (0.785) \\
Xtncor & & -2.079^{**} & -2.126^{***} & -2.988^{***} \\
& & (0.816) & (0.817) & (0.837) \\
Xtroa & & 0.594 & 0.469 & 2.815^{***} \\
& & (0.853) & (0.860) & (0.931) \\
Xter & & 0.778^{***} & 0.801^{***} & 0.443^{*} \\
& & (0.178) & (0.179) & (0.241) \\
Xtidis & & 0.098^{**} & 0.098^{**} & 0.135^{***} \\
& & (0.039) & (0.039) & (0.042) \\
Xtninor & & 0.002 & 0.001 & 0.011^{*} \\
& & (0.006) & (0.006) & (0.006) \\
Xtlr & & 0.165^{***} & 0.167^{***} & -0.063 \\
& & (0.047) & (0.047) & (0.062) \\
Xtag & & -0.014 & -0.015 & 0.014 \\
& & (0.028) & (0.028) & (0.029) \\
Xtrep & & -0.054^{**} & -0.051^{**} & -0.011 \\
& & (0.026) & (0.026) & (0.025) \\
fc & & & -0.019 & 0.060 \\
& & & (0.016) & (0.151) \\
Xfc\_1fc\_rwata\_1 & & & & -0.602^{***} \\
& & & & (0.082) \\
Xfc\_1fc\_llpr\_1 & & & & -1.179 \\
& & & & (1.055) \\
Xfc\_1fc\_ncor\_1 & & & & 0.101 \\
& & & & (1.002) \\
Xfc\_1fc\_roa\_1 & & & & -3.137^{**} \\
& & & & (1.394) \\
Xfc\_1fc\_er\_1 & & & & 0.404 \\
& & & & (0.302) \\
Xfc\_1fc\_idis\_1 & & & & -0.036 \\
& & & & (0.068) \\
Xfc\_1fc\_ninor\_1 & & & & 0.026^{**} \\
& & & & (0.012) \\
Xfc\_1fc\_size\_1 & & & & 0.006 \\
& & & & (0.005) \\
Xfc\_1fc\_lr\_1 & & & & 0.168^{*} \\
& & & & (0.093) \\
Xfc\_1fc\_ag\_1 & & & & -0.055 \\
& & & & (0.035) \\
Constant & -0.013^{*} & -0.112 & -0.114 & -0.152 \\
& (0.008) & (0.080) & (0.080) & (0.095) \\
\midrule
Observations & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} \\
R$^{2}$ & \multicolumn{1}{c}{0.050} & \multicolumn{1}{c}{0.112} & \multicolumn{1}{c}{0.112} & \multicolumn{1}{c}{0.196} \\
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.048} & \multicolumn{1}{c}{0.099} & \multicolumn{1}{c}{0.099} & \multicolumn{1}{c}{0.176} \\
Residual Std. Error & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.007} \\
F Statistic & \multicolumn{1}{c}{21.410$^{***}$} & \multicolumn{1}{c}{9.112$^{***}$} & \multicolumn{1}{c}{8.777$^{***}$} & \multicolumn{1}{c}{9.848$^{***}$} \\
\bottomrule
\multicolumn{5}{c}{*\textit{p} < 0.1; **\textit{p} < 0.05; ***\textit{p} < 0.01} \\
\end{longtable}%
\end{ThreePartTable}
\end{document}
但是,我收到了错误:
Command \bfseries invalid in math mode. ...bfseries(2)} &{\bfseries(3)} & {\bfseries
答案1
以下是使用dcolumn
或 的两个版本siunitx
:
\documentclass[12pt,a4paper,twoside]{article}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=3cm,rmargin=3cm }
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[flushleft, online]{threeparttablex}
\usepackage{dcolumn}
\begin{document}
\begin{ThreePartTable}
\footnotesize
\setlength{\tabcolsep}{4.5pt}
\begin{TableNotes}[para]%
\footnotesize
\item[]This is ordinary least square.
\end{TableNotes}
\begin{longtable}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} }
\caption{OLS}
\label{tab1}\\
\insertTableNotes\\
\toprule
\midrule
\multicolumn{1}{c}{\bfseries{}} &\multicolumn{1}{c}{\bfseries(1)} & \multicolumn{1}{c}{\bfseries(2)} &\multicolumn{1}{c}{\bfseries(3)} & \multicolumn{1}{c}{\bfseries(4)} \\
\endfirsthead
\caption{-- continued from previous page}\\
\toprule
& \multicolumn{1}{c}{\bfseries(1)} & \multicolumn{1}{c}{\bfseries(2)} &\multicolumn{1}{c}{\bfseries(3)} & \multicolumn{1}{c}{\bfseries(4)}\\
\midrule
\endhead
\bottomrule
\addlinespace
\multicolumn{5}{r}{\footnotesize Continued on next page} \\
\endfoot
\addlinespace
\endlastfoot %
\midrule
treat1SEC & 0.083^{***} & 0.080^{***} & 0.071^{***} & 0.070^{***} \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
treat1CB & -0.002 & 0.007 & -0.001 & 0.002 \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
tfcSEC & -0.151^{***} & -0.157^{***} & -0.139^{***} & -0.126^{***} \\
& (0.017) & (0.017) & (0.023) & (0.022) \\
tfcCB & -0.006 & -0.028 & -0.011 & -0.012 \\
& (0.017) & (0.018) & (0.023) & (0.022) \\
Xtrwata & & -0.165^{***} & -0.162^{***} & 0.278^{***} \\
& & (0.045) & (0.045) & (0.068) \\
Xtllpr & & 2.825^{***} & 2.819^{***} & 4.304^{***} \\
& & (0.732) & (0.732) & (0.785) \\
Xtncor & & -2.079^{**} & -2.126^{***} & -2.988^{***} \\
& & (0.816) & (0.817) & (0.837) \\
Xtroa & & 0.594 & 0.469 & 2.815^{***} \\
& & (0.853) & (0.860) & (0.931) \\
Xter & & 0.778^{***} & 0.801^{***} & 0.443^{*} \\
& & (0.178) & (0.179) & (0.241) \\
Xtidis & & 0.098^{**} & 0.098^{**} & 0.135^{***} \\
& & (0.039) & (0.039) & (0.042) \\
Xtninor & & 0.002 & 0.001 & 0.011^{*} \\
& & (0.006) & (0.006) & (0.006) \\
Xtlr & & 0.165^{***} & 0.167^{***} & -0.063 \\
& & (0.047) & (0.047) & (0.062) \\
Xtag & & -0.014 & -0.015 & 0.014 \\
& & (0.028) & (0.028) & (0.029) \\
Xtrep & & -0.054^{**} & -0.051^{**} & -0.011 \\
& & (0.026) & (0.026) & (0.025) \\
fc & & & -0.019 & 0.060 \\
& & & (0.016) & (0.151) \\
Xfc\_1fc\_rwata\_1 & & & & -0.602^{***} \\
& & & & (0.082) \\
Xfc\_1fc\_llpr\_1 & & & & -1.179 \\
& & & & (1.055) \\
Xfc\_1fc\_ncor\_1 & & & & 0.101 \\
& & & & (1.002) \\
Xfc\_1fc\_roa\_1 & & & & -3.137^{**} \\
& & & & (1.394) \\
Xfc\_1fc\_er\_1 & & & & 0.404 \\
& & & & (0.302) \\
Xfc\_1fc\_idis\_1 & & & & -0.036 \\
& & & & (0.068) \\
Xfc\_1fc\_ninor\_1 & & & & 0.026^{**} \\
& & & & (0.012) \\
Xfc\_1fc\_size\_1 & & & & 0.006 \\
& & & & (0.005) \\
Xfc\_1fc\_lr\_1 & & & & 0.168^{*} \\
& & & & (0.093) \\
Xfc\_1fc\_ag\_1 & & & & -0.055 \\
& & & & (0.035) \\
Constant & -0.013^{*} & -0.112 & -0.114 & -0.152 \\
& (0.008) & (0.080) & (0.080) & (0.095) \\
\midrule
Observations & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} & \multicolumn{1}{c}{1,620} \\
R$^{2}$ & \multicolumn{1}{c}{0.050} & \multicolumn{1}{c}{0.112} & \multicolumn{1}{c}{0.112} & \multicolumn{1}{c}{0.196} \\
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.048} & \multicolumn{1}{c}{0.099} & \multicolumn{1}{c}{0.099} & \multicolumn{1}{c}{0.176} \\
Residual Std. Error & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.008} & \multicolumn{1}{c}{0.007} \\
F Statistic & \multicolumn{1}{c}{21.410$^{***}$} & \multicolumn{1}{c}{9.112$^{***}$} & \multicolumn{1}{c}{8.777$^{***}$} & \multicolumn{1}{c}{9.848$^{***}$} \\
\bottomrule
\multicolumn{5}{c}{*\textit{p} < 0.1; **\textit{p} < 0.05; ***\textit{p} < 0.01} \\
\end{longtable}%
\end{ThreePartTable}
\begin{ThreePartTable}
\footnotesize
\begin{TableNotes}[para]%
\footnotesize
\item[]This is ordinary least square.
\end{TableNotes}
\sisetup{
table-space-text-pre={(},
table-space-text-post={***},
input-open-uncertainty = ,
input-close-uncertainty = ,
table-format=-1.4,
table-text-alignment=right,
table-align-text-pre = false,
table-align-text-post = false
}
\begin{longtable}{lSSSS }
\caption{OLS}
\label{tab1}\\
\insertTableNotes\\
\toprule
& {\bfseries(1)} & {\bfseries(2)} &{\bfseries(3)} & {\bfseries(4)}\\
\endfirsthead
\caption{-- continued from previous page}\\
\toprule
& {\bfseries(1)} & {\bfseries(2)} &{\bfseries(3)} & {\bfseries(4)}\\
\midrule
\endhead
\bottomrule
\addlinespace
\multicolumn{5}{r}{\footnotesize Continued on next page} \\
\endfoot
\addlinespace
\endlastfoot %
\midrule
treat1SEC & 0.083{***} & 0.080{***} & 0.071{***} & 0.070{***} \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
treat1CB & -0.002 & 0.007 & -0.001 & 0.002 \\
& (0.014) & (0.014) & (0.016) & (0.015) \\
tfcSEC & -0.151{***} & -0.157{***} & -0.139{***} & -0.126{***} \\
& (0.017) & (0.017) & (0.023) & (0.022) \\
tfcCB & -0.006 & -0.028 & -0.011 & -0.012 \\
& (0.017) & (0.018) & (0.023) & (0.022) \\
Xtrwata & & -0.165{***} & -0.162{***} & 0.278{***} \\
& & (0.045) & (0.045) & (0.068) \\
Xtllpr & & 2.825{***} & 2.819{***} & 4.304{***} \\
& & (0.732) & (0.732) & (0.785) \\
Xtncor & & -2.079{**} & -2.126{***} & -2.988{***} \\
& & (0.816) & (0.817) & (0.837) \\
Xtroa & & 0.594 & 0.469 & 2.815{***} \\
& & (0.853) & (0.860) & (0.931) \\
Xter & & 0.778{***} & 0.801{***} & 0.443{*} \\
& & (0.178) & (0.179) & (0.241) \\
Xtidis & & 0.098{**} & 0.098{**} & 0.135{***} \\
& & (0.039) & (0.039) & (0.042) \\
Xtninor & & 0.002 & 0.001 & 0.011{*} \\
& & (0.006) & (0.006) & (0.006) \\
Xtlr & & 0.165{***} & 0.167{***} & -0.063 \\
& & (0.047) & (0.047) & (0.062) \\
Xtag & & -0.014 & -0.015 & 0.014 \\
& & (0.028) & (0.028) & (0.029) \\
Xtrep & & -0.054{**} & -0.051{**} & -0.011 \\
& & (0.026) & (0.026) & (0.025) \\
fc & & & -0.019 & 0.060 \\
& & & (0.016) & (0.151) \\
Xfc\_1fc\_rwata\_1 & & & & -0.602{***} \\
& & & & (0.082) \\
Xfc\_1fc\_llpr\_1 & & & & -1.179 \\
& & & & (1.055) \\
Xfc\_1fc\_ncor\_1 & & & & 0.101 \\
& & & & (1.002) \\
Xfc\_1fc\_roa\_1 & & & & -3.137{**} \\
& & & & (1.394) \\
Xfc\_1fc\_er\_1 & & & & 0.404 \\
& & & & (0.302) \\
Xfc\_1fc\_idis\_1 & & & & -0.036 \\
& & & & (0.068) \\
Xfc\_1fc\_ninor\_1 & & & & 0.026{**} \\
& & & & (0.012) \\
Xfc\_1fc\_size\_1 & & & & 0.006 \\
& & & & (0.005) \\
Xfc\_1fc\_lr\_1 & & & & 0.168{*} \\
& & & & (0.093) \\
Xfc\_1fc\_ag\_1 & & & & -0.055 \\
& & & & (0.035) \\
Constant & -0.013{*} & -0.112 & -0.114 & -0.152 \\
& (0.008) & (0.080) & (0.080) & (0.095) \\
\midrule
Observations & {1,620} & {1,620} & {1,620} &{1,620} \\
R$^{2}$ & {0.050} & {0.112} & {0.112} & {0.196} \\
Adjusted R$^{2}$ & {0.048} & {0.099} & {0.099} & {0.176} \\
Residual Std. Error & {0.008} & {0.008} & {0.008} & {0.007} \\
F Statistic & {21.410{***}} & {9.112{***}} & {8.777{***}} & {9.848{***}} \\
\bottomrule
\multicolumn{5}{c}{*\textit{p} < 0.1; **\textit{p} < 0.05; ***\textit{p} < 0.01} \\
\end{longtable}%
\end{ThreePartTable}
\end{document}