{"id":337,"date":"2022-02-14T02:16:40","date_gmt":"2022-02-13T18:16:40","guid":{"rendered":"https:\/\/www.scijournal.org\/articles\/?p=337"},"modified":"2023-05-22T06:14:28","modified_gmt":"2023-05-21T22:14:28","slug":"latex-tables","status":"publish","type":"post","link":"https:\/\/www.scijournal.org\/articles\/latex-tables","title":{"rendered":"How to Create LaTeX tables"},"content":{"rendered":"\n<p>LaTeX tables Creating is a versatile document creation tool that allows you to present information in many different ways.&nbsp;<\/p>\n\n\n\n<p>If you plan to include large quantities of data or information in your document, you may wish to include it in a table.&nbsp; The good news is that LaTeX lets you create customized tables using a few key commands. Let\u2019s examine how to create <em>LaTeX<\/em> <em>tables <\/em>and customize them according to your needs.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_67_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69df6f0bb0070\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69df6f0bb0070\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Creating_LaTeX_Tables_Using_Table_and_Tabular_Environments\" title=\"Creating LaTeX Tables Using Table and Tabular Environments\">Creating LaTeX Tables Using Table and Tabular Environments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Creating_Tables_With_a_Fixed_Length\" title=\"Creating Tables With a Fixed Length\">Creating Tables With a Fixed Length<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#How_to_Merge_Rows_and_Columns\" title=\"How to Merge Rows and Columns\">How to Merge Rows and Columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Creating_Latex_Tables_That_Span_Multiple_Pages\" title=\"Creating Latex Tables That Span Multiple Pages\">Creating Latex Tables That Span Multiple Pages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Positioning_the_Latex_Tables_Text\" title=\"Positioning the Latex Tables Text\">Positioning the Latex Tables Text<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Captioning_Labelling_and_Referencing_Latex_Tables\" title=\"Captioning, Labelling, and Referencing Latex Tables\">Captioning, Labelling, and Referencing Latex Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Creating_a_List_of_Latex_Tables\" title=\"Creating a List of Latex Tables\">Creating a List of Latex Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Adding_Colors_to_Tables\" title=\"Adding Colors to Tables\">Adding Colors to Tables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Changing_the_Color_of_Different_Table_Elements\" title=\"Changing the Color of Different Table Elements\">Changing the Color of Different Table Elements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Showing_Tables_in_Landscape\" title=\"Showing Tables in Landscape&nbsp;\">Showing Tables in Landscape&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Final_Thoughts\" title=\"Final Thoughts\">Final Thoughts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Frequently_Asked_Questions\" title=\"Frequently Asked Questions\">Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Q1_What_is_a_LaTeX_table\" title=\"Q1. What is a LaTeX table?\">Q1. What is a LaTeX table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Q2_How_do_I_make_a_table_in_LaTeX\" title=\"Q2. How do I make a table in LaTeX?\">Q2. How do I make a table in LaTeX?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Q3_How_do_I_make_multiple_lines_in_a_table_in_LaTeX\" title=\"Q3. How do I make multiple lines in a table in LaTeX?\">Q3. How do I make multiple lines in a table in LaTeX?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Q4_What_is_the_difference_between_table_and_tabular_in_LaTeX\" title=\"Q4. What is the difference between table and tabular in LaTeX?\">Q4. What is the difference between table and tabular in LaTeX?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\/#Further_Reading\" title=\"Further Reading\">Further Reading<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"creating-latex-tables-using-table-and-tabular-environments\"><span class=\"ez-toc-section\" id=\"Creating_LaTeX_Tables_Using_Table_and_Tabular_Environments\"><\/span>Creating LaTeX Tables Using Table and Tabular Environments<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To create LaTeX tables, you must first create a <em>table <\/em>environment followed by a <em>tabular <\/em>environment. The <em>table <\/em>environment lets you create captions while the <em>tabular <\/em>environment enables you to insert values and margins for your table.<\/p>\n\n\n\n<p>You can create a tabular environment using the commands <em>\\begin{tabular}{&#8230;.}<\/em> and <em>\\end{tabular}<\/em>.<\/p>\n\n\n\n<p>An example of a simple table is shown below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{center}\n\\begin{tabular}{ |c|c|c| } \n \\hline\n cellnumber1 &amp; cellnumber2 &amp; cellnumber3 \\\\ \n cellnumber4 &amp; cellnumber5 &amp; cellnumber6 \\\\ \n cellnumber7 &amp; cellnumber8 &amp; cellnumber9 \\\\ \n \\hline\n\\end{tabular}\n\\end{center}\n\n<\/pre><\/div>\n\n\n<p>The above code creates three-column latex tables, each with three rows not separated by a line. We used the command <em>{ |c|c|c| }<\/em> to first declare three columns separated by vertical lines. The \u201c<em>c<\/em>\u201d in the above command informs LaTeX to center the values in each column. Alternatively, we could use the parameter \u201c<em>r<\/em>\u201d to align the column text towards the right, or \u201c<em>l<\/em>\u201d to align it to the left.<\/p>\n\n\n\n<p>We used the command <em>\\hline <\/em>twice to add horizontal borders to the top and bottom of the table. You can use this command as many times as needed to add horizontal borders to your tables.<\/p>\n\n\n\n<p>We then inserted our cell values \u201c<em>cellnumber1<\/em>\u201d, \u201c<em>cellnumber2<\/em>\u201d, and so forth. Each value in the code <em>cellnumber1 &amp; cellnumber2 &amp; cellnumber3 \\\\<\/em> is separated by an \u201c<em>&amp;<\/em>\u201d. This \u201c<em>&amp;<\/em>\u201d informs LaTeX to separate the values individually in columns, while the \u201c\\\\\u201d indicates the end of a row.<\/p>\n\n\n\n<p>If we wanted to set up latex tables with horizontal lines between each row and no lines between columns, the code would resemble:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{center}\n\\begin{tabular}{||c c c c||} \n \\hline\n Column1 &amp; Column2 &amp; Column3 &amp; Column4 \\\\ &#x5B;0.5ex] \n \\hline\\hline\n 1 &amp; 232 &amp; 486 &amp; 524 \\\\ \n \\hline\n2 &amp; 38 &amp; 39 &amp; 413 \\\\\n \\hline\n 3 &amp; 747 &amp; 831 &amp; 5201 \\\\\n \\hline\n 4 &amp; 604 &amp; 13211 &amp; 8184 \\\\\n \\hline\n 5 &amp; 96 &amp; 233 &amp; 1681 \\\\ &#x5B;1ex] \n \\hline\n\\end{tabular}\n\\end{center}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used the command <em>&nbsp;\\hline\\hline<\/em>. This creates a gap between the first row containing our table headers and the second row that contains the first set of values.&nbsp;<\/p>\n\n\n\n<p>We also used the command <em>\\begin{tabular}{||c c c c||} <\/em>to describe the table format. We wanted four values separated but without vertical column lines. The \u201c<em>||\u201d<\/em> in this code inserts a double line at each side of the latex tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-tables-with-a-fixed-length\"><span class=\"ez-toc-section\" id=\"Creating_Tables_With_a_Fixed_Length\"><\/span>Creating Tables With a Fixed Length<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In some cases, you may wish to create LaTeX tables with a fixed length. LaTeX allows you to do this, and also create tables where the length of each column is fixed. This is made possible by using the <em>array<\/em> package with the command <em>\\usepackage{array}<\/em>. We demonstrate this in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage{array}\n\\begin{document}\n\\begin{center}\n\\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | } \n  \\hline\n  cell1 example text example text example text &amp; cell2 &amp; cell3 \\\\ \n  \\hline\n  cell1 example text example text example text &amp; cell5 &amp; cell6 \\\\ \n  \\hline\n  cell7 &amp; cell8 &amp; cell9 \\\\ \n  \\hline\n\\end{tabular}\n\\end{center}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>The above code produces latex tables where the width of the first column is much greater than the width of the second and third columns. We achieved this using the command <em>m{5em}<\/em> to set the first column\u2019s length as 5em. We then set the length of the other two columns to 1cm using the code <em>m{1cm}<\/em>.&nbsp;<\/p>\n\n\n\n<p>The parameter \u201c<em>m\u201d<\/em> informs LaTeX to place the text in the middle of the column. Alternatively, we could have used the parameter \u201c<em>p<\/em>\u201d to place the text at the top of the column and \u201c<em>b<\/em>\u201d to place it at the bottom.<\/p>\n\n\n\n<p>You should note that you do not need to set the width of each cell, as LaTeX tables can do this automatically. It is possible to make each cell equal width with the spaces distributed equally using the <em>tabularx<\/em> package. This package can be loaded using the command <em>\\usepackage{tabularx}<\/em>.<\/p>\n\n\n\n<p>We show an example of a 3 x 2 table where each cell is equal in width below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage{tabularx}\n\\begin{document}\n\\begin{tabularx}{0.7\\textwidth} { \n  | &gt;{\\raggedright\\arraybackslash}X \n  | &gt;{\\centering\\arraybackslash}X \n  | &gt;{\\raggedleft\\arraybackslash}X | }\n \\hline\n cell1 &amp; cell2 &amp; cell3 \\\\\n \\hline\n cell4  &amp; cell5  &amp; cell6  \\\\\n\\hline\n\\end{tabularx}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above LaTeX Tables, the text in the first column is aligned left, the second column text is aligned to the middle, while the third column text is aligned to the right. We achieved this using the code&nbsp;<\/p>\n\n\n\n<p><em>| &gt;{\\raggedright\\arraybackslash}X&nbsp;<\/em><\/p>\n\n\n\n<p><em>| &gt;{\\centering\\arraybackslash}X&nbsp;<\/em><\/p>\n\n\n\n<p><em>&nbsp;| &gt;{\\raggedleft\\arraybackslash}X | }<\/em><\/p>\n\n\n\n<p>We also set the table width to be 70% of the document text width using the command <em>0.8\\textwidth<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-merge-rows-and-columns\"><span class=\"ez-toc-section\" id=\"How_to_Merge_Rows_and_Columns\"><\/span>How to Merge Rows and Columns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaTeX tables can be set to merge columns or rows to make larger cells. This can be done using the command <em>\\multicolumn<\/em>. We can demonstrate this with the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage{multirow}\n\\begin{document}\n\\begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|  }\n \\hline\n \\multicolumn{4}{|c|}{Dog Listings} \\\\\n \\hline\n Dog Name&amp; Breed&amp;Weight&amp;Height\\\\\n \\hline\n Alfie  &amp; Rottweiler    &amp;33&amp;   24\\\\\n Romeo&amp;   Dachshund  &amp;14  &amp;8\\\\\n Charles &amp;Golden Retriever &amp; 28&amp;  20\\\\\n \\hline\n\\end{tabular}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used the command <em>\\multicolumn{4}{|c|}{Dog Listings} \\\\<\/em> to produce latex tables where the first row consists of a single cell made from merging four columns.&nbsp;<\/p>\n\n\n\n<p>The <em>{4}<\/em> in this code describes the number of columns we wish to combine. The <em>{|c|}<\/em> command informs LaTeX to center the text and place a vertical line on each side. The code <em>{Dog Listings}<\/em><strong> <\/strong>places the text \u201c<em>Dog Listing<\/em>\u201d inside the merged cell.<\/p>\n\n\n\n<p>If we wanted to create a table where the second, third, and fourth rows are merged, the code would be:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage{multirow}\n\\begin{document}\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c| } \n\\hline\ncolumn1 &amp; column2 &amp; column3 \\\\\n\\hline\n\\multirow{3}{4em}{Three Rows Combined} &amp; number2 &amp; number3 \\\\ \n&amp; number5 &amp; number6 \\\\ \n&amp; number8 &amp; number9 \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>The above code includes the command <em>\\multirow{3}{4em}{Three Rows Combined} &amp; number2 &amp; number3 \\\\<\/em> where \u201c<em>3<\/em>\u201d specifies that three rows should be combined, and <em>4em<\/em> indicates the column width.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-latex-tables-that-span-multiple-pages\"><span class=\"ez-toc-section\" id=\"Creating_Latex_Tables_That_Span_Multiple_Pages\"><\/span>Creating Latex Tables That Span Multiple Pages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You may need to create a very long table to include a large amount of information at some point. If such a table is expected to span across multiple pages, you will need to use the <em>longtable<\/em> package in LaTeX. This package can be added using the command <em>\\usepackage{longtable}<\/em> in the document preamble.<\/p>\n\n\n\n<p>We demonstrate how to create multi-page LaTeX tables using the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage{longtable}\n \n\\begin{document}\n \n \\begin{longtable}&#x5B;c]{| c | c |}\n \\caption{Caption for Table.\\label{long}}\\\\\n \n \\hline\n \\multicolumn{2}{| c |}{First Row in the Table}\\\\\n \\hline\n Value1 &amp; Value2\\\\\n \\hline\n \\endfirsthead\n \n \\hline\n \\multicolumn{2}{|c|}{Continuation of same Table \\ref{long}}\\\\\n \\hline\n Value1 &amp; Value2\\\\\n \\hline\n \\endhead\n \n \\hline\n \\endfoot\n \n \\hline\n \\multicolumn{2}{| c |}{End of this Table}\\\\\n \\hline\\hline\n \\endlastfoot\n \nContent for the table\\\\\nContent for the table\\\\\nContent for the table\\\\\nContent for the table\\\\\nContent for the table\\\\\nContent for the table\\\\\nContent for the table\\\\\n ...\nContent for the table\\\\\n \\end{longtable}\n\n<\/pre><\/div>\n\n\n<p>The <em>longtable<\/em> environment works similarly to the <em>tabular<\/em> environment. However, it allows latex tables to span across multiple pages without letting LaTeX\u2019s page-breaking algorithm ruin the format. Using the <em>longtable<\/em> package also requires you to use certain commands in your code. The ones we used are shown below.<\/p>\n\n\n\n<p><em>\\endfirsthead<\/em>: The text displayed above this command will show at the start of your table on the first page.<\/p>\n\n\n\n<p><em>\\endhead<\/em>: The text placed before this command and after <em>\\endfirsthead<\/em> will be shown at the start of the table on each page with the exception of the first page.<\/p>\n\n\n\n<p><em>\\endfoot<\/em>: The text placed before this command and after <em>\\endhead<\/em> will be shown at the bottom of your table on each page with the exception of the first page.<\/p>\n\n\n\n<p><em>\\endlastfoot<\/em>: The text placed before this command and after <em>\\endfoot<\/em> will be shown at the bottom of your table on the last page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"positioning-the-latex-tables-text\"><span class=\"ez-toc-section\" id=\"Positioning_the_Latex_Tables_Text\"><\/span>Positioning the Latex Tables Text<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the above examples, we spoke briefly about aligning text in their respective columns. However, it is possible to perform more complex positioning using a float <em>table <\/em>environment in LaTeX tables.<\/p>\n\n\n\n<p>We demonstrate this in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\begin{document}\nThe following table is positioned here:\n\\begin{table}&#x5B;h!]\n\\centering\n \\begin{tabular}{||c c c c||} \n \\hline\n Column1 &amp; Column2 &amp; Column2 &amp; Column3 \\\\ &#x5B;0.5ex] \n \\hline\\hline\n 4 &amp; 47 &amp; 5434 &amp; 732\\\\ \n 7 &amp; 58 &amp; 41 &amp; 9414\\\\\n 3 &amp; 63 &amp; 38 &amp; 6801\\\\\n11 &amp; 89 &amp; 2300 &amp; 4313\\\\\n 23 &amp; 101 &amp; 813 &amp; 7488\\\\ &#x5B;1ex] \n \\hline\n \\end{tabular}\n\\end{table}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above code, the \u201c<em>h!<\/em>\u201d informs LaTeX to place the table underneath instead of its default position. Some of these parameters are explained below:<\/p>\n\n\n\n<ul><li><em>h<\/em> places the table \u201chere\u201d in approximate terms.<\/li><li><em>H<\/em> places the table exactly at this location.<\/li><li><em>t <\/em>places the table at the top of your page.<\/li><li><em>b <\/em>places the table at the bottom of your page.<\/li><li><em>p <\/em>places the table in a specified special page.<\/li><li><em>!<\/em> informs LaTeX to override its default parameters for table placement.<\/li><\/ul>\n\n\n\n<p>Underneath the code mentioned above, we used the command <em>\\centering<\/em> to center our table relative to the float\u2019s container element. The command <em>\\[1ex]<\/em> tells LaTeX to add extra space to this cell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"captioning-labelling-and-referencing-latex-tables\"><span class=\"ez-toc-section\" id=\"Captioning_Labelling_and_Referencing_Latex_Tables\"><\/span>Captioning, Labelling, and Referencing Latex Tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaTeX allows you to caption, label, and reference your table with the help of the <em>table<\/em> environment. We demonstrate how to do each of these in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\begin{document}\nTable \\ref{table:1} is a referenced element in this document.\n\\begin{table}&#x5B;h!]\n\\centering\n \\begin{tabular}{||c c c c||} \n \\hline\n Column1 &amp; Column2 &amp; Column2 &amp; Column3 \\\\ &#x5B;0.5ex] \n \\hline\\hline\n 4 &amp; 47 &amp; 5434 &amp; 732\\\\ \n 7 &amp; 58 &amp; 41 &amp; 9414\\\\\n 3 &amp; 63 &amp; 38 &amp; 6801\\\\\n11 &amp; 89 &amp; 2300 &amp; 4313\\\\\n 23 &amp; 101 &amp; 813 &amp; 7488\\\\ &#x5B;1ex] \n \\hline\n \\end{tabular}\n\\caption{This is the caption for this table.}\n\\label{table:1}\n\\end{table}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above code, the command <em>\\caption{This is the caption for this table.}<\/em> creates the caption \u201cThis is the caption for this table\u201d. We placed this command underneath <em>\\end{table}<\/em> so the caption was placed under the table.<\/p>\n\n\n\n<p>We included the command <em>\\label{table:1}<\/em> to label the table. After setting this label, we can reference it using the <em>\\ref{table:1}<\/em> command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-a-list-of-latex-tables\"><span class=\"ez-toc-section\" id=\"Creating_a_List_of_Latex_Tables\"><\/span>Creating a List of Latex Tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaTeX allows you to create a list of all the tables in your document using the <em>\\listoftables<\/em> command. This list will feature the caption used for each table. These demonstrate how to create a list of tables in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\begin{document}\n\\listoftables\n\\vspace{5pt}\nTable \\ref{table:1} is a referenced element in this document.\n\\begin{table}&#x5B;h!]\n\\centering\n \\begin{tabular}{||c c c c||} \n \\hline\n Column1 &amp; Column2 &amp; Column2 &amp; Column3 \\\\ &#x5B;0.5ex] \n \\hline\\hline\n 4 &amp; 47 &amp; 5434 &amp; 732\\\\ \n 7 &amp; 58 &amp; 41 &amp; 9414\\\\\n 3 &amp; 63 &amp; 38 &amp; 6801\\\\\n11 &amp; 89 &amp; 2300 &amp; 4313\\\\\n 23 &amp; 101 &amp; 813 &amp; 7488\\\\ &#x5B;1ex] \n \\hline\n \\end{tabular}\n\\caption{This is the caption for this table.}\n\\label{table:1}\n\\end{table}\n\\begin{table}&#x5B;h!]\n\\centering\n\\begin{tabular}{||c c c c||} \n \\hline\n Column1 &amp; Column2 &amp; umnColumn2 &amp; Col3 \\\\ &#x5B;0.5ex] \n \\hline\\hline\n  7 &amp; 613 &amp; 2718 &amp; 8500 \\\\\n 8 &amp; 79 &amp; 632 &amp; 7210 \\\\ &#x5B;1ex] \n \\hline\n\\end{tabular}\n\\caption{This caption is for the second table.}\n\\label{table:2}\n\\end{table}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>After compiling the above code, we will see each table mentioned in a <em>List of Tables<\/em> section. These tables will be numbered and their corresponding pages will also be shown in this section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adding-colors-to-tables\"><span class=\"ez-toc-section\" id=\"Adding_Colors_to_Tables\"><\/span>Adding Colors to Tables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to add some color to your tables, you can do this with the help of the <em>xcolor<\/em> package and using the <em>table<\/em> options. We demonstrate how to do this in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage&#x5B;table]{xcolor}\n\\setlength{\\arrayrulewidth}{0.5mm}\n\\setlength{\\tabcolsep}{18pt}\n\\renewcommand{\\arraystretch}{2.5}\n\\begin{document}\n{\\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}\n\\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|  }\n\\hline\n\\multicolumn{3}{|c|}{Dog Listings} \\\\\n\\hline\n Dog Name&amp; Breed&amp;Weight\\\\\n\\hline\n Alfie  &amp; Rottweiler    &amp;33\\\\\n Romeo&amp;   Dachshund  &amp;14\\\\\n Charles &amp;Golden Retriever &amp; 28\\\\\n\\hline\n\\end{tabular}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above code we used the command <em>\\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}. <\/em>The \u201c<em>3\u201d<\/em> indicates which row to start using the colors from. <em>{green!80!yellow!50}<\/em> specifies the row color for odd rows while <em>{green!70!yellow!40}<\/em> specifies the color for even rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"changing-the-color-of-different-table-elements\"><span class=\"ez-toc-section\" id=\"Changing_the_Color_of_Different_Table_Elements\"><\/span>Changing the Color of Different Table Elements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage&#x5B;table]{xcolor}\n\\setlength{\\arrayrulewidth}{0.5mm}\n\\setlength{\\tabcolsep}{18pt}\n\\renewcommand{\\arraystretch}{2.5}\n\\newcolumntype{s}{&gt;{\\columncolor&#x5B;HTML]{AAACED}} p{3cm}}\n\\arrayrulecolor&#x5B;HTML]{DB5800}\n\\begin{document}\n\\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|  }\n\\hline\n\\rowcolor{lightgray} \\multicolumn{3}{|c|}{Dog Listings} \\\\\n\\hline\n Dog Name&amp; Breed&amp;Weight\\\\\n\\hline\n Alfie  &amp; Rottweiler    &amp;33\\\\\n\\rowcolor{gray}\n Romeo&amp;   Dachshund  &amp;14\\\\\n Charles &amp;Golden Retriever &amp; \\cellcolor&#x5B;HTML]{AA0044} 28\\\\\n\\hline\n\\end{tabular}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we set the table line color using the command <em>\\arrayrulecolor<\/em>. We then set the background color of a single cell using the command <em>\\cellcolor<\/em>.&nbsp;<\/p>\n\n\n\n<p>We set the background color of an entire row using the command \\rowcolor.&nbsp;<\/p>\n\n\n\n<p>We also set the background color for an entire column using the command <em>\\newcolumntype{s}{&gt;{\\columncolor[HTML]{AAACED}} p{3cm}}<\/em>. This code defines the column type as \u201c<em>s<\/em>\u201d and the column text alignment as \u201c<em>p<\/em>\u201d. The column color is set using HTML format as <em>AAACED<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"showing-tables-in-landscape\"><span class=\"ez-toc-section\" id=\"Showing_Tables_in_Landscape\"><\/span>Showing Tables in Landscape&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In some cases you may need to rotate a table to help it fit onto a single page. This is helpful if the table contains too many columns. It is possible to rotate LaTeX tables in many different ways.<\/p>\n\n\n\n<p>One of the easiest methods is using the package <em>rotating<\/em>. You can load this package using the command <em>\\usepackage{rotating} <\/em>in the preamble. You will also need to replace the <em>table<\/em> environment with a<em> sidewaystable<\/em> environment provided by the <em>rotating<\/em> package.<\/p>\n\n\n\n<p>We demonstrate this using the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{sidewaystable}&#x5B;h!]\n  \\begin{center}\n  \\caption{Rotated table.}\n  \\label{tab:table1}\n  \\begin{tabular}{l|S|r}\n      \\toprule\n      \\textbf{Column1} &amp; \\textbf{Column2} &amp; \\textbf{Column3}\\\\\n      11 &amp; 22 &amp; 33 \\\\\n    \\midrule\n    1 &amp; 58 &amp; a\\\\\n    2 &amp; 62 &amp; b\\\\\n    3 &amp; 64 &amp; c\\\\\n    \\bottomrule\n  \\end{tabular}\n  \\end{center}\n\\end{sidewaystable}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"final-thoughts\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As you can see, LaTeX allows you to insert tables relatively easily. You have plenty of options for customizing your tables. so try experimenting with the different commands discussed above and start producing professional-looking tables in your next LaTeX document. You can also learn how to create more complex LaTeX tables by watching the <a href=\"https:\/\/www.youtube.com\/watch?v=y7B7FbnJbas&amp;ab_channel=TJR\" target=\"_blank\" rel=\"noopener\">video<\/a> below.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"LaTex Tutorial 8: Advanced Tables\" width=\"1200\" height=\"900\" src=\"https:\/\/www.youtube.com\/embed\/y7B7FbnJbas?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Some frequently asked questions related to LaTeX tables are shown below.<\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1630925904025\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q1_What_is_a_LaTeX_table\"><\/span>Q1. What is a LaTeX table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A LaTeX table is simply a table in LaTeX. These tables can have multiple rows and columns that can be customized to your liking.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1630925911798\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q2_How_do_I_make_a_table_in_LaTeX\"><\/span>Q2. How do I make a table in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can make a simple table in LaTeX using the commands <em>\\begin{tabular}{&#8230;.}<\/em> and<em> \\end{tabular}<\/em>, and by specifying your table text\/values in between them.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1630925982694\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q3_How_do_I_make_multiple_lines_in_a_table_in_LaTeX\"><\/span>Q3. How do I make multiple lines in a table in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can create horizontal lines in LaTeX tables using the command <em>\\hline<\/em>. You can create vertical lines using <em>\\begin{tabular}{||c c c c||}<\/em>, in which \u201c<em>|<\/em>\u201d denotes a vertical line and its position relative to the cell text.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1630925990988\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q4_What_is_the_difference_between_table_and_tabular_in_LaTeX\"><\/span>Q4. What is the difference between table and tabular in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p><em>Table <\/em>and <em>tabular<\/em> are two important environments in LaTeX tables. The <em>tabular<\/em> environment allows you to typeset content in your rows and columns. The <em>table<\/em> environment functions as the container for your floating material that contains the <em>tabular <\/em>environment.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<h2 class=\"gb-headline gb-headline-c8ee9dc0 gb-headline-text\"><span class=\"ez-toc-section\" id=\"Further_Reading\"><\/span><strong>Further Reading<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>LaTex Tutorial<\/strong><\/p>\n\n\n\n<ol><li><a href=\"https:\/\/www.scijournal.org\/articles\/pros-and-cons-of-using-latex\">27 Pros and Cons of Using LaTex for Scientific Writing<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-document\">6 easy steps to create your first Latex document examples<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/circuit-diagrams-in-latex\">How to add circuit diagrams in Latex<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-font\">How to change Latex font and font size<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-table-of-contents\">How to create a Latex table of contents<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/footnotes-in-latex\">How to create footnotes in LaTeX and how to refer to them, using the builtin commands<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/glossaries-in-latex\">How to create Glossaries in LaTeX<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\">How to create plots in Latex \u2013 codes and examples<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/symbols-in-latex\">How to create symbols in LaTeX \u2013 commands for Latex greek alphabet<\/a>\u00a0<\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/graphs-in-latex\">How to drawing graphs in Latex \u2013 vector graphics with tikz<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/source-code-in-latex\">How to highlight source code in LaTeX<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/image-in-latex\">How to insert an image in LaTeX \u2013 Managing Latex figure and picture<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-bullet-points\">How to Itemize and Number List \u2013 Adding Latex Bullet Points<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/hyperlinks-in-latex\">How to make hyperlink in latex \u2013 Clickable links<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/reference-in-latex\">How to reference in Latex \u2013 5 steps to bibliography with Bibtex<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-packages\">How to use Latex Packages with examples<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-paragraphs\">How to use LaTeX paragraphs and sections<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-installation-guide\">LaTeX Installation Guide \u2013 Easy to follow steps to install LaTex<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-equations-and-math\">Learn to typeset and align Latex equations and math<\/a><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>LaTeX tables Creating is a versatile document creation tool that allows you to present information in many different ways.&nbsp; If you plan to include large quantities of data or information in your document, you may wish to include it in a table.&nbsp; The good news is that LaTeX lets you create customized tables using a &#8230; <a title=\"How to Create LaTeX tables\" class=\"read-more\" href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\" aria-label=\"Read more about How to Create LaTeX tables\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":338,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/337"}],"collection":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":5,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":5580,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/337\/revisions\/5580"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/media\/338"}],"wp:attachment":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}