我想要使用包创建一个 4 列表格\usepackage[flushleft]{threeparttable}
。该表基于以下代码。
\begin{table} [h]
\caption{Main results after endogeneity correction}
\label{tab:main_results_endog}
\centering
\SingleSpacedXI
\begin{subtable}[c]{\textwidth}
\caption{Cost analysis \label{tbl:main_results_cost}}
\centering
\begin{threeparttable}
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}c}
\hline\hline
& MRO & Repair & Maintenance \\ \hline
$XXX$ & $-0.070^{***}$ & $-0.098^{***}$ & XXX \\
& (0.0032) & (0.0033) & XXX \\
Car attributes controls & Yes & Yes & Yes \\
Driver attributes controls & Yes & Yes & Yes \\
$R^2$ & 0.286 & 0.296 & XXX \\
\# Observations & 19,410,026 & 19,410,026 & XXX \\ \hline\hline
\end{tabular}
\begin{tablenotes}
\item Note: Standard errors in parentheses (* p $<$ 0.05, ** p $<$ 0.01, *** p $<$ 0.001)
\end{tablenotes}
\end{threeparttable}
\end{subtable}
\quad%
\begin{subtable}[c]{\textwidth}
\caption{Frequency analysis \label{tbl:main_results_frequency}}
\centering
\begin{threeparttable}
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}c}
\hline\hline
& MRO & Repair & Maintenance \\ \hline
$XXX$ & $0.055^{***}$ & $0.052^{***}$ & XXX \\
& (0.0025) & (0.0025) & XXX \\
Car attributes controls & Yes & Yes & Yes \\
Driver attributes controls & Yes & Yes & Yes \\
$R^2$ & 0.266 & 0.286 & XXX \\
\# Observations & 18,522,387 & 18,522,387 & XXXX \\ \hline\hline
\end{tabular}
\begin{tablenotes}
\item Note: Standard errors in parentheses (* p $<$ 0.05, ** p $<$ 0.01, *** p $<$ 0.001)
\end{tablenotes}
\end{threeparttable}
\end{subtable}
\end{table}
代码输出下表。为什么最后会有多余的一列?我该如何删除它?
答案1
您当前指定两个tabular
环境都有 11 [!] 列。由于两个表实际上都只有 4 列,因此解决格式问题的最佳方法是将两个实例都更改为
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}c}
到
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}}
当然,这是假设您对其余四列的规格没有异议。如果您不满意,请随意提出更好的选择。
补充三条评论:
由于您几乎没有使用包装的机制
threeparttable
,因此我会避免产生其开销。为了简化确保表格适合文本块的工作,我将从切换
tabular
到tabularx
环境(目标宽度为)并用\textwidth
替换第二个实例。p{0.35\textwidth}
X
我会摆脱那些看起来很忙碌的
\hline\hline
指令,并用包的规则绘制宏替换它们booktabs
:\toprule
、\midrule
和\bottomrule
。
\documentclass{article} % or some other suitable document class
\usepackage{subcaption,booktabs,tabularx}
\begin{document}
\begin{table}[h]
\caption{Main results after endogeneity correction}
\label{tab:main_results_endog}
% \SingleSpacedXI % huh?
\begin{subtable}{\textwidth}
\caption{Cost analysis}
\label{tbl:main_results_cost}
\begin{tabularx}{\textwidth}{@{} p{0.35\textwidth} l c X @{}}
\toprule
& MRO & Repair & Maintenance \\
\midrule
\textit{XXX} & $-0.070^{***}$ & $-0.098^{***}$ & XXX \\
& (0.0032) & (0.0033) & XXX \\
\addlinespace
Car attributes controls & Yes & Yes & Yes \\
Driver attributes controls & Yes & Yes & Yes \\
$R^2$ & 0.286 & 0.296 & XXX \\
\# Observations & 19,410,026 & 19,410,026 & XXX \\
\bottomrule
\end{tabularx}
\smallskip\footnotesize
Note: Standard errors in parentheses; $^{*}$ $p < 0.05$, $^{**}$ $p < 0.01$, $^{***}$ $p < 0.001$.
\end{subtable}
\bigskip\bigskip
\begin{subtable}{\textwidth}
\caption{Frequency analysis}
\label{tbl:main_results_frequency}
\begin{tabularx}{\textwidth}{@{} p{0.35\textwidth} l c X @{}}
\toprule
& MRO & Repair & Maintenance \\
\midrule
\textit{XXX} & $0.055^{***}$ & $0.052^{***}$ & XXX \\
& (0.0025) & (0.0025) & XXX \\
\addlinespace
Car attributes controls & Yes & Yes & Yes \\
Driver attributes controls & Yes & Yes & Yes \\
$R^2$ & 0.266 & 0.286 & XXX \\
\# Observations & 18,522,387 & 18,522,387 & XXXX \\
\bottomrule
\end{tabularx}
\smallskip\footnotesize
Note: Standard errors in parentheses; $^{*}$ $p < 0.05$, $^{**}$ $p < 0.01$, $^{***}$ $p < 0.001$.
\end{subtable}
\end{table}
\end{document}