1How to use it
- Type your data in the grid of Figure 1(a), or copy a range of cells in Excel, LibreOffice or Google Sheets and paste it into any cell: the grid takes the size of what you pasted.
- Set the alignment of each column with the
l,candrbuttons above it. Text usually reads best left aligned, numbers right aligned. - Choose a rule style and whether the first row is a bold header. The preview in Figure 1(b) follows every change.
- Press Copy LaTeX and paste the result into the body of your document, then replace the placeholder caption and the
tab:your-labellabel. The caption sits above the table, as is the convention for tables, and the float uses[htbp]so LaTeX can place it.
2Choosing a rule style
Table 1 compares the three styles. Most journals and the LaTeX typesetting community recommend booktabs: three horizontal rules of two weights and no vertical lines, which is also how the tables on this page are set.
| Style | Rules in the output | Column spec | Package |
|---|---|---|---|
| booktabs | \toprule, \midrule, \bottomrule | l c r | booktabs |
| Simple borders | \hline around every row | |l|c|r| | none |
| No borders | none, or \hline with Row lines | l c r | none |
Table 1. The three rule styles, for columns aligned left, center and right.
The booktabs commands are not part of the LaTeX kernel. The generated code starts with a comment that reminds you of it; the package itself goes in the preamble, before \begin{document}:
\usepackage{booktabs}3Pasting from Excel or CSV
A range copied from a spreadsheet arrives as tab-separated text, one line per row, and is split on the tabs, so a cell such as Smith, J. stays in one piece. Text without tabs is read as CSV: cells are split on commas, and a field in double quotes may contain commas. Empty lines are skipped and every cell is trimmed.
Only a paste that contains a tab or a line break replaces the table. A single value pasted into a cell goes into that cell, as in any text field.
4Special characters
Cell contents are treated as plain text. The ten characters that LaTeX reserves (\ & % $ # _ { } ~ ^) are escaped in the output, so R&D becomes R\&D and 50% becomes 50\%, and the table compiles on the first try. The other side of this rule: LaTeX typed in a cell, such as $x^2$, is printed literally. Add math or macros after pasting the code into your document, where the live LaTeX preview shows the result.