+5 votes
63 views
in Office by (242k points)
reopened
Create an table in LaTeX - this is how it works

1 Answer

+3 votes
by (1.6m points)
 
Best answer

Create LaTeX tables with tabular

Would you like to summarize your results in a table in LaTeX? Here we show you all the basic functions of LaTeX tables..

image image

Tables are a widely used tool in LaTeX that can be used to summarize results. The safe handling of tables is necessary in order to create qualitatively appealing documents. In our tipps + tricks article we show you the basic commands for the manual creation of tables in LaTeX.

Create LaTeX tables with tabular

Simple table environment

Tables in LaTeX are an extensive area that can be expanded with further imported packages. You can use the booktabs package to make tables, for example, clearer. We limit ourselves here to the possibilities offered by Standard LaTeX, ie without importing additional packages. A simple table environment is created with tabular as follows:

\begin{tabular}[ Platzierung ]{ Format }
Inhalt der Tabelle
\end{tabular}

The columns are formatted individually in LaTeX. The following values ​​are available for the format:

c centered text
r right-aligned text
l left-aligned text
p {"x" cm} Column should be "x" cm wide
| inserts a vertical line between the columns (via [ALT] + [<] )
c centered text
r right-aligned text
l left-aligned text
p {"x" cm} Column should be "x" cm wide
| inserts a vertical line between the columns (via [ALT] + [<] )

The table can optionally be defined as a floating object via its placement . Otherwise the table always appears where it was defined in the code. You can replace the "Placement" option with the following values:

H here exactly at the point
b bottom Top of page
t Top End of page
p position places the table on an extra page, especially for float objects
H here genau an der Stelle
b bottom Seitenanfang
t top Seitenende
p position platziert die Tabelle auf einer Extra-Seite, eigens für Float-Objekte

Table

content The content of the table is entered line by line and every line break is \\ implemented. The individual columns of each row, which for example represent a cell in Excel, are & separated from each other with the ampersand. If we now insert an example content into our table, the following example results:

\begin{tabular}[h]{lcr}
Spalte 1 & Spalte 2 & Spalte 3 \\
heise & tipps & tricks \\
\end{tabular}

image

Table

lines You can use the vertical line to make your tables more attractive. To do this, simply enter the line in the format of the table. The lines can also \hline be separated from one another using a horizontal line with the command . You can use it to customize your table as needed. We are expanding our example again with newly learned approaches:

\begin{tabular}[h]{l|c|r}
Spalte 1 & Spalte 2 & Spalte 3 \\
\hline
heise & tipps & tricks \\
\end{tabular}

image



Table labeling and labels If you would like to label the table as well, so that it may later be included in the list of tables, LaTeX naturally also covers this:

\begin{tabular}[h]{lcr}
\caption{Beschreibung der Tabelle}
Spalte 1 & Spalte 2 & Spalte 3 \\
heise & tipps & tricks \\
\label{tab:heisetabelle}
\end{tabular}

You can now \ref{tab:heisetabelle} reference in the text using the table. You can adapt the description of the table individually. LaTeX will automatically number the description for you.

Multicolumn

With "Multicolumn" you can combine several columns into one cell. You can define the alignment of the cell using the format values. The command for this is: \multicolumn{Anzahl n}{Ausrichtung}{Inhalt}. Multicolumn overwrites previously defined lines. This you have to set it again on alignment, for example |c . Our minimal example then complements as follows:

\begin{tabular}{c|c|c|l|r}
\hline
\multicolumn{3}{c}{heise} & tipps & tricks \\
\hline
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular}

image

...