Making Tables with LaTeX

Tables are used to display information visually for a reader. They provide structure for the text in order to guide the comprehension of the reader. In this post, we will learn how to make basic tables.

Basic Table

For a beginner, the coding for developing a table is somewhat complex. Below is the code followed by the actual table. We will examine the code after you see it.

\documentclass{article}
\begin{document}
   \begin{tabular}{ccc}
      \hline
      Vegetables & Fruits & Nuts\\
      \hline
      lettace & mango & almond\\
      spinach & apple & cashews\\
      \hline
   \end{tabular}
\end{document}

1

We will now go through the code.

  • Line 1 is the preamble and tells LaTeX that we are making an article document class.
  • Line 2 is the declaration  to begin the document environment
  • Line 3 is where the table begins.  We create a tabular environment. IN the second set of curly braces we used the argument “ccc” this tells LaTeX to create 3 columns and each column should center the text. IF you wan left justification to use “l” and “r” for right justification
  • Line 4 uses the “\hline” declaration this draws the top horizontal line
  • Line 5 includes information for the first row of the columns. The information in the columns is separated by an ampersand ( & ) at the end of this information you use a double forward slash ( \\ ) to make the next row
  • Line 6 is a second “\hline” to close the header of the table
  • Line 7 & 8 are additional rows of information
  • Line 9 is the final “\hline” this is for the bottom of the table
  • Lines 10 & 11 close the tabular environment and the document

This is an absolute basic table. We made three columns with centered text with three rows as well.

Table with Caption

A table almost always has a caption in academics. The caption describes the contents of the table. We will use the example above but we need to add several lines of code. This is described below

  • We need to create a “table” environment. We will wrap this around the “tabular” environment
  • We need to use the “\caption” declaration with the name of the table inside curly braces after we end the “tabular” environment but before we end the table environment.
  • We will also add the “\centering” declaration near the top of the code so the caption is directly under the table

Below is the code followed by the example.

\documentclass{article}
\begin{document}
   \begin{table}
      \centering
      \begin{tabular}{ccc}
         \hline
            Vegetables & Fruits & Nuts\\
         \hline
            lettace & mango & almond\\
            spinach & apple & cashews\\
         \hline
      \end{tabular}
         \caption{Example Table}
   \end{table}
\end{document}

1.png

Conclusion

We explored how to develop a basic table in LaTeX. There are many more features and variations to how to do this. This post just provides some basic ideas on how to approach this.

Leave a Reply