Monday, December 5, 2022
HomeLaTexHow to Generate Table in LaTeX

How to Generate Table in LaTeX

Learn to Create Tables in LaTeX, Describing Some Table Attributes, Table Formatting, Combine Multiple Tables, Importing Table from Excel

  1. Creating Table in LaTeX
  2. Some Table Attributes
  3. Table Formatting
  4. Combining Multiple Tables
  5. Import Table from Excel

How to create table using LaTeX by using table and tabular environments, this type of questions. We also learn to format table, entering data, merging in table and importing the table from MS-Excel. First we’ll create a basic table which contains no data.

Creating Table in LaTeX

In LaTeX, we are often create tables through a mix of table setting and therefore the tabular environment. The table settings part correspondence to the beginning of a table, caption of a table, and also defines the float of the table such as display the table in center, display the table text in center, left and right etc.

The Tabular environment uses different command and operators to perform different actions on table and on text contains in the table. For example, newline symbols || as row separators and ampersands & as column separators.

Now just look at the code given in the following table. This code is written in LaTex for creating an empty table without containing any contents in the cells. \begin{table}[] command initiate the start of table, \centering align the table into center and caption is used for table heading as shown below :

Some Table Attributes

Now, we are adding some data into the table rows and columns. Vertical lines are used for separating the columns of a table. This vertical line (|) is passed as an associate argument for the tabular settings (e.g.\begin{tabular}{l|c|r} ). Letters between these vertical lines tells us that where we align the content on the left part of the cell (l), to the center of the cell (c) or to the right of the cell (r) for all columns. Only one letter and a vertical line in front of them or in the middle of the letters for multiple columns should be used to show the vertical line in the table. If we want to separate Rows, Rows separators could be added with the \hline command. As we discussed above, we add the caption of table using ‘Caption’ command and passing the caption of table as an argument.

 Following code generated the given table:

Table Formatting

table may contain a caption, number of rows, and a number of columns. Rows are exists in row group and columns are exists in column group. The intersection of Rows and columns are called cells. Data is entered in the cells of a table. In the following code we format the table by putting the bolded horizontal lines to clarify the table contents, add extra space between rows and follow the professional template for this table:

Combining Multiple Rows & Columns

Of course it is also attainable to mix the 2 options, to make a cell spanning multiple rows and multiple columns. Multicolumn command is used to merge the columns with one another not the content of columns, as the content we use a multirow command to merge multiple rows. After that another multicolumn command also added to specify the number of rows which we want to use to merge. Following table shows the results of ‘Multirow’ and ‘Multicolumn’:

Import Table from Excel

When writing research papers or documents, sometimes we need to represent a lot amount of data in the form of tables. If we write this data into table by hand in LaTeX by hand then it will take a lot of time and may also be prompted to some kind of errors. To prevent such errors and to save time, .csv (comma separated value) files can be imported in LaTeX directly without any difficulty. Different programs such as openOffice-Calc, emacs org-mode or Excel can export datasheets in the form of .csv files.

  • CSV files cannot be used directly.
  • In the LaTeX but to use the data those CSV files contains we can write up the above given code which will import the data from .csv file named ‘names.csv’ easily without taking a lot of time and any error. 
  • And it will generate the table which will look like this:

Finally, in this blog we learn that how can we work with tables in LaTeX. First we create a simple table in the LaTeX and then we enter some data into it. After that we apply some attributes of table like borders, aligning contents, bold etc. Sometimes we need to merge the two or multiple columns or multiple rows. We also cover this topic in this blog. Lastly as we know that sometimes we represent a lot of data in the form of tables, but we cannot directly write it into LaTeX. As it is time consuming and error prone task. The solution of this problem is to just write the data in other programs like Excel and open-Office etc. Then just export their datasheets as .csv files, then you can easily import those .csv files into LaTeX. These are some operation which we can done in LaTeX on tables, a lot of others can also be done in LaTeX. We also write a blog that tells that how to make CV using LaTeX.



Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular