Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exporting 'fragment' LaTeX tables via collect export

    Is it possible to export a "fragment" of table using the new collect suite of commands?

    I want to use collect export to create a LaTeX table file, say table.tex, and then refer to it in my LaTeX document. I can do this via
    Code:
    collect export table.tex, tableonly
    which exports only the table rather than a whole compilable LaTeX document. I can then refer to the table in the main document via \input{table.tex}. The table in this case is wrapped in table environment. For example:
    Code:
    sysuse auto, clear
    regress price mpg
    etable, export(table.tex, tableonly)
    produces
    Code:
    \begin{table}[!h]
    \centering
    \begin{tabular}{ll}
    \cline{1-2}
    \multicolumn{1}{r}{} &
      \multicolumn{1}{c}{price} \\
    \cline{1-2}
    \multicolumn{1}{l}{Mileage (mpg)} &
      \multicolumn{1}{r}{-238.894} \\
    \multicolumn{1}{l}{} &
      \multicolumn{1}{r}{(53.077)} \\
    \multicolumn{1}{l}{Intercept} &
      \multicolumn{1}{r}{11253.061} \\
    \multicolumn{1}{l}{} &
      \multicolumn{1}{r}{(1170.813)} \\
    \multicolumn{1}{l}{Number of observations} &
      \multicolumn{1}{r}{74} \\
    \cline{1-2}
    \end{tabular}
    \end{table}
    What I would like to have instead is something like the "fragment" option in esttab package to suppress table opening and closing, that is to export the tabular section only. The reason I want this is to be able to use my own custom table setup within LaTeX. One example (among others) is to use the threeparttable environment to have proper table notes:

    Code:
    \begin{table}[!h]
      \centering
      \begin{threeparttable}[b]
        \begin{tabular}{ll}
          \input{table.tex}
        \end{tabular}
      \end{threeparttable}
      \begin{tablenotes}[para,flushleft]
        \item \textit{Notes:} #1
      \end{tablenotes}
    \end{table}
    Is this possible to do in collect suite?

  • #2
    Following up on my question a while ago, and a couple of back-and-forth with StataCorp, I realized that there is no option in collect export to export LaTeX tables with only the tabular environment.

    Now, thanks to Kit Baum, my fragtextab routine is up on SSC.

    Stata 17 introduced a collect suite of commands (collect, table, and etable), all of which can export as LaTeX files. TeX options include tableonly for exporting only the table to the specified file, which is useful for including the table in a LaTeX document via \input{} command. However, the output includes a table environment in addition to the tabular environment, which prevents using more advanced LaTeX packages such as threeparttable. There is no option to "fragmentize", i.e., to suppress the table's opening and closing specifications.

    fragtextab does just that! It takes a .tex file, and throws everything out except the tabular section:

    \begin{tabular}
    ...
    \end{tabular}


    It can be used right after collect commands, although not necessarily. fragtextab can edit any .tex file specified by using option and save to any .tex file specified by saving option.

    Here is a simple example of how it works:
    Code:
    sysuse auto, clear
    regress price mpg
    estimates store m1
    etable, est(m1) export(table1.tex, replace) // full compilable document
    fragtextab                                  // only tabular environment

    Comment


    • #3
      You could do that using collect style tex, nobegintable

      Code:
      sysuse auto, clear
      regress price mpg
      estimates store m1
      etable, est(m1)
      collect style tex , nobegintable
      collect export c:\temp\foo.tex, tableonly replace
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Maarten Buis I wasn't aware of this! Thanks for letting me know -- this makes it more straightforward.

        Comment

        Working...
        X