latex - Latex Table - latex tutorial
How to Create Tables in Latex?
- Generating a table of contents can be done with a few simple commands.
- LaTeX will use the section headings to create the table of contents and there are commands to create a list of figures and a list of tables as well.
Code to create a table of contents:
After compiling the .tex file two times, you will get the following table of contents:
step1 content design in latex
- The generation of a list of figures and tables works the same way.
- Dummy figure and table are put in the lists in the appendix of my document:
Sample Code:
After compiling two times again, the lists will be generated like this:
step2 content design in latex table
- A lot of times, it is necessary to have data nicely structured in a table. LaTeX offers an environment for table creation.
- For this purpose we use the table and tabular as well as the center environment.
- The table environment merely holds our other environments and allows to add a caption to our table.
- The actual data is contained in the tabular environment and we center the table on the page using the center environment.
- The table I use for demonstration look like this:
caption in latex table
- The according code contains ampersands & as column seperators and newline symbols \\ as row seperators.
- The vertical lines are passed as an argument to the tabular environment (e.g. \begin{tabular}{l|c||r} ) and the letters tell whether we want to align the content to the left (l), to the center (c) or to the right (r) for each column.
- Row seperators can be added with the \hline command. The \caption and \label commands can be used in the same way as for pictures.
Sample Code:
- There are two disadvantages of writing tables by hand as described.
- While it works for small tables similar to the one in our example, it can take a long time to enter a large amount of data by hand.
- Most of the time the data will be collected in form of a spreadsheet and we don't want to enter the data twice.
- Furthermore once put into LaTeX tables, the data can not be plotted anymore and is not in a useful form in general.
caption content in latex table
Coding requires just a few changes:
- I suggest you to try out all the features of LaTeX tables by yourself.
- It's usually faster to use a tool like excel to format your content and then let the pgfplots package autogenerate a table for you.