How to make a LaTeX paper table: Grammar and formatting points
Explain the basic writing methods of LaTeX paper tables, including the division of labor between tabular and table environments, column alignment, three-line tables, crossing columns and rows, and how to deal with tables that are over-wide or cross-page, and attach a checklist.
Key points of this article
- The tabular is responsible for arranging the grid, and the table floating environment is responsible for the title, number and position. The two have different divisions of labor and should not be confused.
- Three-line tables are commonly used in academic papers. With the help of toprule, midrule, and bottomrule of the booktabs macro package, they are more standardized than full vertical lines.
- Column format characters l, c, r, p {width} determine the alignment. It is recommended to right-align or unify decimal places for numeric columns.
- When the table exceeds the center of the page, needs to span two pages, or needs to merge cells, there are corresponding commands. First determine the type of problem and then choose a method.
- Compile twice and check the numbers, cross-references and line types one by one. Recompile after making changes to confirm that the results are correct.
When many people write a paper form in LaTeX for the first time, they copy a piece of \begin{tabular} code from the Internet and paste it in. As a result, compilation errors are reported, columns are not aligned, or the grid lines do not match the requirements of the journal template. The problem usually does not lie in a certain command, but in not clarifying what each environment is responsible for, and not choosing the right line type.
This article is written for thesis authors, graduates, and coursework writers who need to create their own tables in LaTeX source files. After reading, you will be able to judge which environment to use, handwrite a three-line table that conforms to academic habits, and know how to deal with extra-wide tables, cross-pages, and merged cells.
The methods discussed here are general and applicable to any environment that can compile LaTeX normally. If the source file you have needs to be translated or modified on the web, there are relevant instructions in the FAQ at the end of the article.
How to write a LaTeX paper form? One sentence conclusion
Use the table floating environment to wrap the title and number, use tabular to draw the grid inside, and use the three-line table of booktabs as the line type. If you encounter special situations such as template regulations, cross-page or extra-wide, use the corresponding method.
| your situation | Recommended practices | reason |
|---|---|---|
| Ordinary experimental data table, requiring number and title | Add tabular for table environment and booktabs for line environment. | Numbering and citations are automatically maintained, and positions are arranged by the typesetting system |
| Journal or school template has specified line style | Write according to the macro packages and commands provided by the template | Template provisions take precedence. Adding lines yourself may be returned for modification. |
| Table width exceeds page center | Scale with resizebox, or use tabularx to automatically assign column widths instead | Direct support will exceed the edge of the page and affect typesetting. |
| The form needs to span multiple pages | Using longtable environment | tabular and table environments cannot span pages |
| Need to merge cells | Use multicolumn to merge columns and multirow to merge rows. | Both need to load the corresponding macro package in the introductory area |
Before you start: Confirm these points first
- Confirm whether the macro package has been loaded. Booktabs, multirow, tabularx and other macro packages need to be loaded using
\usepackagein the preamble area. If it is missing, the compilation will report an error such as Undefined control sequence. First read the error line in the log, and then return to the introductory area to supplement it. - Confirm whether the template has regulations. Many schools and journals will provide special .cls or .sty files, and the table line style, font size, and table title position may have been defined. In this case, the template should be followed first and there is no need to set it up yourself.
- First draw the table structure on paper. The number of columns, number of header levels, and whether there are merged cells must be determined before starting. If you write code without thinking clearly about the structure, you will often have to redo the entire section if you want to change it.
- Confirm whether numbering and cross-referencing are required. Tables in papers are usually numbered and should be referred to in the text using the
\refcitation instead of handwriting "Table 1". Once the handwritten numbers are added or subtracted from the table, they have to be modified one by one, and it is easy to miss the changes. - Confirm single column or double column. In double-column templates, wide tables should use the table* environment to make the table span two columns; single-column templates usually use the table environment directly. The final position of the table is arranged by LaTeX according to space, the position parameters are only suggestions.
Five steps to write a three-line table by hand
- Load booktabs in the introduction area. Write
\usepackage{booktabs}. The horizontal lines of the three-line table are provided by it. Do not use the default\hlineto draw full grid lines, otherwise the layout will appear crowded. - Wrap the table with the table environment. Start writing the table environment, first write
\centeringto center the table, and then write\caption{表题}. The title of a Chinese paper is usually located above the table, and the specific location is subject to the requirements of the school or journal. - Use tabular to define column format. In the curly braces after tabular, each letter corresponds to a column: l is left aligned, c is centered, and r is right aligned. Columns with longer text can be written in the form p{4cm}, and the line will wrap automatically after setting the width.
- Draw three lines and fill in the content. Write
\topruleabove the table header,\midrulebelow the table header, and\bottomruleat the end of the table. Separate columns with&and write\\at the end of each line. Only these three types of horizontal lines are used throughout the table, no vertical lines are added. - Add tags and cite them in the text. Write
\label{tab:result}after\caption, and write "as shown in table~\ref{tab:result}" in the text. The tilde generates non-breaking spaces to prevent the word "table" and the number from being split into two lines. After compiling twice, the cross-reference will show the correct number.
Check each item after completion
| Check items | How to see | What to do if there is a problem |
|---|---|---|
| Numbers and references | The table number in the PDF is consistent with the text reference and is not displayed?? | Compile again; if there is still ??, check whether the spellings of label and ref are consistent. |
| table width | Whether the right side of the table exceeds the page edge | Scale with resizebox, or use tabularx to set the total width instead |
| linear | There are only three thick lines, no vertical lines and redundant horizontal lines | Delete redundant vertical bar symbols and \hline, and use three-line commands instead. |
| Number alignment | Whether decimal points in the same column are aligned vertically | Numeric columns use r or center instead, with consistent decimal places |
| special characters | Whether %, &, _, # in the text are written in the form of \%, \&, etc. | Escape in text, do not escape subscript symbols in formulas |
| compile warning | Is there any prompt such as Overfull hbox in the log? | Adjust the column width or text according to the prompted line number, and compile again to confirm |
📊 Core comparison: How to choose between three commonly used table environments
| environment | suitable form | Things to note |
|---|---|---|
| tabular | Ordinary table with fixed column width and short content | Without numbers and titles, usually placed in a table environment |
| tabularx | A table that needs to occupy the full width of the page and has some columns with long text | You need to load the tabularx macro package and specify the X column type for the automatically expanded column |
| longtable | Tables with many rows that need to span two pages | Comes with title and cross-page continuation table settings, which cannot be placed in the table environment |
❓ Frequently Asked Questions (FAQ)
1. The text in the table is too long, how to wrap it automatically?
Use p{width} in column format, such as p{5cm}, and the text will automatically wrap within the set width. Text after line breaks is aligned at both ends by default. If you need left alignment, you can add \raggedright in front of the cell.
2. Why doesn’t the table appear where I want it?
table is a floating body, and LaTeX will automatically arrange the position according to the remaining space on the page, so it does not necessarily follow the text quotation. Adjustment of position parameters can only give suggestions and cannot be forced to be fixed. If you really need to fix the position, you can adjust the order of the text, or move the table near the appropriate paragraph without affecting the layout.
3. Can I directly convert Excel tables into LaTeX code?
Can. Many online conversion websites and desktop office software plug-ins can export tables into tabular code. After generation, it still needs to be manually checked according to the line type and alignment requirements of this article. A common problem is that the generated code has a full grid of vertical lines and needs to be changed to a three-line table. When using online conversion, be careful not to upload data that has not yet been made public.
4. My LaTeX source file was given by someone else and I want to translate it or modify it on the web page. What should I do?
OmniDoc supports the translation of LaTeX source code packages. The output can be bilingual or translated only. Tables, formulas and pictures will be retained as much as possible. UniDoc web page editor (app.unidoc.top) supports round-trip conversion between Word and LaTeX, which is suitable for situations where you need to switch and modify between the two formats. No matter which method is used, the table structure and numbers must be checked after conversion or translation, and the results of machine translation require manual confirmation.
5. Is it better to have as many macro packages in the introduction area?
Not recommended. Only loading the actually used macro packages can reduce conflicts between macro packages and make it easier to troubleshoot errors. Commonly used macro packages related to tables are booktabs, multirow, tabularx and longtable, which can be loaded on demand.
📝 Summary
The key to LaTeX paper tables is to first use the table environment to manage titles and numbers, then use tabular to define column formats, and uniformly use three-line tables. When encountering over-wide, cross-page or merged cells, select the corresponding macro package and environment, compile it twice and check each item one by one.
Open OmniDoc and edit, convert or translate your LaTeX document


