1

I have an external table that is is produced by a statistics package Stata like this:

sysuse auto
estimates clear
eststo, title("OLS"): reg price mpg
esttab using "~/Desktop/table.tex", replace title(My OLS Model)

The file table.tex looks like this:

\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{My OLS Model}
\begin{tabular}{l*{1}{c}}
\hline\hline
            &\multicolumn{1}{c}{(1)}\\
            &\multicolumn{1}{c}{price}\\
\hline
mpg         &      -238.9\sym{***}\\
            &     (-4.50)         \\
[1em]
\_cons      &     11253.1\sym{***}\\
            &      (9.61)         \\
\hline
\(N\)       &          74         \\
\hline\hline
\multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}

I input it into a LaTeX main document like this:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\input{table.tex}
\end{document}

I have two questions:

  1. Is it possible to add a note at the bottom of this table in the main document that could be edited in the main file (rather than modifying table.tex file)?
  2. Is it possible to overwrite the caption from the main document?
2
  • Should the note be similar in width to the tabular? That is, just like the \multicolumn notes in table.tex?
    – Werner
    Oct 12, 2016 at 22:07
  • @Werner No, I would like them to span the width of the page.
    – dimitriy
    Oct 12, 2016 at 22:09

1 Answer 1

2

You're not using a \label inside the table to reference it, nor are you using the optional argument to \caption for a different LoT entry. So, we can just redefine \caption to do whatever you want, including supplying a new caption.

Additionally, we use etoolbox to patch \end{tabular} for the insertion of arbitrary content via \AfterEndEnvironment{tabular}:

enter image description here

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{table.tex}
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{My OLS Model}
\begin{tabular}{l*{1}{c}}
\hline\hline
            &\multicolumn{1}{c}{(1)}\\
            &\multicolumn{1}{c}{price}\\
\hline
mpg         &      -238.9\sym{***}\\
            &     (-4.50)         \\
[1em]
\_cons      &     11253.1\sym{***}\\
            &      (9.61)         \\
\hline
\(N\)       &          74         \\
\hline\hline
\multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{filecontents*}

\usepackage{booktabs,etoolbox}

\AfterEndEnvironment{tabular}{\tabularendstuff}
\newcommand{\tabularendstuff}{}

\begin{document}

% Update the \caption
\begingroup
\let\oldcaption\caption
\renewcommand{\caption}[1]{\oldcaption{A new caption}}
\renewcommand{\tabularendstuff}{\par {\footnotesize This is some arbitrary stuff added after \texttt{tabular}.}}
\input{table.tex}
\endgroup

% Original table
\input{table.tex}

\end{document}

All changes are grouped to limit their scope to the current table/tabular.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .