Quero ter uma tabela de 4 colunas usando package \usepackage[flushleft]{threeparttable}
. A tabela é baseada nos códigos abaixo.
\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}
Os códigos geram a tabela abaixo. Por que há coluna extra no final? Como devo removê-lo?
Responder1
No momento, você está especificando que ambos tabular
os ambientes tenham 11 colunas [!]. Como ambas as tabelas possuem apenas 4 colunas, a melhor maneira de corrigir o problema de formatação é alterar ambas as instâncias de
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}lcp{0.35\textwidth}c}
para
\begin{tabular}{p{0.35\textwidth}lcp{0.35\textwidth}}
Isso pressupõe, é claro, que você esteja de acordo com as especificações das quatro colunas restantes. Se não estiver, sinta-se à vontade para fazer escolhas melhores.
Três comentários adicionais:
Como você mal usa o maquinário do
threeparttable
pacote, evito incorrer em despesas gerais.Para simplificar o trabalho de garantir que as tabelas caibam dentro do bloco de texto, eu mudaria de
tabular
paratabularx
ambientes (com larguras alvo de\textwidth
) e substituiria a segunda instância dep{0.35\textwidth}
porX
.Eu me livraria das
\hline\hline
diretivas aparentemente ocupadas e as substituiria pelas macros de desenho de regras dobooktabs
pacote:\toprule
,\midrule
, e\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}