benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
70 stars 17 forks source link

Remove last \\ from esttab fragment #13

Closed de-barros closed 6 years ago

de-barros commented 6 years ago

esttab with the fragment option generates a file that ends in \\

Once this fragment is used within a longtabu environment, this causes an additional, empty line. This is because the input command has to end with \\ such as in

\begin{longtabu}{l*{2}{c}}   
\caption{My caption \label{tab:mylabel}} \\
\toprule 
\input{fragment.txt} \\
\bottomrule
\end{longtabu}

Sample output:

image

If possible, kindly remove this additional \\ from the end of the fragment.

benjann commented 6 years ago

Changing the default behavior might not be a good idea because it would break existing applications. However, I took it on the list to add an option to suppress the \ on the last line. In the meantime, try removing the extra line by adding negative space. Try something like

esttab, tex fragment postfoot([-2em])

2em is just a wild guess, you'd have to play around to get this right. Probably there is also an exact way to find out how much vertical space a row consumes (based on stuff like \baselineskip and such).

de-barros commented 6 years ago

You're right - removing it would break existing applications - tabular for example requires the last linebreak. Thanks for your answer though and for adding an option - super helpful! Thanks also for suggesting negative space. For now, I'm just adding a few lines after esttab, to remove it manually:

    insheet using "fragment.txt", clear
    local nob = _N
    replace v1 = subinstr(v1,"\\","",.) in `nob'
    outsheet using "fragment.txt", replace non noq

Obviously, this is crude but it works. I've also tried \[0pt] (in both the fragment and the tex file), as well as \newline and \cr - none of them work. Thanks again - I'm closing this issue.