help texsave
-------------------------------------------------------------------------------
Title

texsave -- Save dataset in LaTeX format.

Syntax

texsave [varlist] using filename [if] [in] [, title(string) size(string) width(string) align(string) location(string) marker(string) autonumber hlines(numlist) footnote(footnote_options) varlabels rowsep(string) frag nonames sw nofix headerlines(stringlist) headlines(stringlist) footlines(stringlist) replace format_options]

where

numlist is a list of numbers with blanks or commas in between (see [U] numlist for details),

stringlist is a list of quoted strings,

footnote_options are

footnote(string [, size(string) align(string)])

and format_options are

bold(stringlist) italics(stringlist) underline(stringlist) slanted(stringlist) smallcaps(stringlist) sansserif(stringlist) monospace(stringlist) emphasis(stringlist)

Description

texsave outputs the dataset currently in memory to filename in LaTeX format. It uses the booktabs and tabularx packages in order to produce publication-quality tables.

Options

title(string) writes out string as a caption above the table.

size(string) specifies the size of your table. Valid size options are tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, and Huge. Alternatively, the user may specify a numeric value between 1 and 10, where 1 corresponds to tiny and 10 corresponds to Huge.

width(string) specifies the width of your table. Lengths can be specified in the same way as for rowsep (see below). The default is \textwidth.

align(string) specifies the column formatting. It generally consists of a sequence of the following specifiers, at least one for each of the columns:

l - a column of left-aligned items

c - a column of centered items

C - a column of centered items; column spacing for all 'C' columns are always the same.

r - a column of right-aligned items

| - a vertical line the full height and depth of the environment

The character '|' (the vertical bar, NOT the alphabetic character 'l') adds vertical lines to the table. For example, if there are three columns, specify align(|l|C|C|) to surround all columns with vertical lines. The default is to left-justify the first column and center and distribute space equally across the rest of the columns, which in the case of three columns corresponds to align(lCC)

location(string) specifies the location of your table in the document. It consists of one or more of the following specifiers:

h - "Here": at the position in the text where the environment appears

t - "Top": at the top of a text page

b - "Bottom": at the bottom of a text page

p - "Page": on a separate page containing no text, only figures and tables

The default is location(tbp).

marker(string) uses LaTeX's \label option to mark your table with the key string.

autonumber writes out "(1)", "(2)"... as the table column names, beginning with column two. This is useful when outputting regression results stored by a command like regsave (if installed).

hlines(numlist) draws horizontal lines below each row specified in numlist. Specify a row's number twice to output a double line. Negative values are interpreted as the distance from the end of the table.

footnote(string [, size(string) align(string)]) writes out string in a left-justified footnote at the bottom of the table. The suboptions allow you to set the size and alignment of the footnote, using the syntax described by the size(string) and align(string) options.

varlabels specifies that variable labels be written in the first line of the table instead of variable names.

rowsep(string) adds vertical spacing of length string to the rows via the \addlinespace command. The length can be expressed in the following units: cm (centimetres), em (the width of the letter M in the current font), ex (the height of the letter x in the current font), in (inches), pc (picas), pt (points) or mm (millimetres). For example, rowsep(1cm) adds one centimeter of vertical space between rows.

frag omits from the output LaTeX code like \begin{document} that is needed to create a standalone document. This makes filename a fragment, which is useful if you plan to link your table to another document via LaTeX's \input{table} command.

nonames specifies that variable names not be written in the first line of the table; the table is to contain data values only.

sw instructs texsave to include macro code that can be read by Scientific Word (SW) so that full SW functionality is retained.

nofix instructs texsave to write out all data, titles and footnotes exactly as they appear in Stata. Many of the non-alphanumeric characters have special meaning in LaTeX, namely _, %, #, $, &, ~, ^^, \, {, }. By default, texsave tries to fix this by adding a backslash (\) in front of these characters. (It is not always successful, though). Specify nofix if you are intentionally outputting LaTeX code and don't want texsave to incorrectly modify it.

headerlines(stringlist) specifies a list of lines of LaTeX code to appear before the table header. Each line of code should be surrounded by quotation marks (see example 5 below).

headlines(stringlist) specifies a list of lines of LaTeX code to appear before the table code in the output. Each line of code should be surrounded by quotation marks (see example 4 below).

footlines(stringlist) specifies a list of lines of LaTeX code to appear after the table code in the output. Each line of code should be surrounded by quotation marks (see example 4 below).

replace overwrites filename.

format_options: bold(), italics(), underline(), slanted(), smallcaps(), sansserif(), monospace(), and emphasis() allow you to format the data values in your table. For example, underline("word1" "word2") underlines all data values containing either "word1" or "word2".

Remarks

It is sometimes difficult to make texsave output a literal "$" because this can be interpreted by Stata as a global macro. For example, "$R^2$" will be incorrectly outputted as "^2$". You can avoid this problem by using the alternative LaTeX syntax "\(R^2\)".

texsave performs some basic error checking. For example, it issues an error if you specify horizontal lines at row values that do not exist. However, it does not check that tables with lots of alignment specifications etc. will compile correctly. It is your responsibility to ensure that you are supplying valid LaTeX code when specifying options such as headlines(), align() etc. See http://en.wikibooks.org/wiki/LaTeX/Tables to learn more about writing LaTeX code for tables.

Notes

texsave has been tested on Scientific WorkPlace 5.0 and TeXShop 2.18 (as supplied by the August 28, 2008 distribution of MacTeX). Please contact the author if you notice problems with other compilers.

Examples

1. Output a table with a title and a footnote.

. sysuse auto.dta, clear

. texsave make mpg trunk if price > 8000 using "example1.tex", title(MPG > and trunk space) footnote("*Variable trunk is measured in cubic feet") repla > ce

2. Output a table with a small font size and some horizontal lines.

. sysuse auto.dta, clear

. texsave make mpg trunk weight length displacement turn using "example2 > .tex" in 1/30, size(2) hlines(3 10/13 19 23 25 28) replace

3. Output a table with half the normal width and LaTeX math code in the footnote.

. sysuse auto.dta, clear

. texsave make mpg trunk if price > 8000 using "example3.tex", title(MPG > and trunk space) width(0.5\textwidth) nofix footnote("*Variable trunk is mea > sured in ft\(^3\)") replace

4. Output a table with additional LaTeX code.

. sysuse auto.dta, clear

. texsave make mpg trunk if price > 8000 using "example4.tex", loc(h) he > adlines("\begin{center}" "My headline" "\end{center}") footlines("My footline > ") replace

5. Output a table with a complicated header and bold-face the first observation.

. sysuse auto.dta, clear

. texsave make mpg trunk if price > 8000 using "example5.tex", bold("Bui > ck") headerlines("& \multicolumn{2}{c}{\textbf{Data}}" "\cmidrule{2-3}\addlin > espace[-2ex]") replace nofix

Author

Julian Reif, University of Chicago

jreif@uchicago.edu

Thanks to Kit Baum for helpful suggestions and feedback.

Also see