This post describes exactly how to use LaTeX to create and customize tables: altering size/spacing, combining cells, using colour to rows or cells, and so forth.

We have the right to begin with among the most basic examples of a table:

egincenteregintabular c c c cell1 & cell2 & cell3 \ cell4 & cell5 & cell6 \ cell7 & cell8 & cell9 endtabularendcenter
 Open this example in

You watching: Vertical centering latex table


The tabular environment is the default LaTeX technique to develop tables. You need to specify a parameter to this environment; right here we use c c c which tells LaTeX that tright here are three columns and also the text inside each one of them have to be centred.

Creating an easy table in LaTeX

The tabular atmosphere offers extra flexibility; for example, you have the right to put separator lines in in between each column:

egincenteregintabular hline cell1 & cell2 & cell3 \ cell4 & cell5 & cell6 \ cell7 & cell8 & cell9 \ hlineendtabularendcenter
 Open this instance in


Here is a summary of the constructions used in the example above:

This declares that three columns, separated by a vertical line, are going to be provided in the table. Each c indicates that the contents of the column will be centred. You deserve to also use r to align the text to the appropriate and also l for left alignment.hlineThis will certainly insert a horizontal line on optimal of the table and at the bottom too. Tright here is no restriction on the variety of times you can usage hline.cell1 & cell2 & cell3 \Each & is a cell separator and the double-backslash \ sets the end of this row.

Below you can watch a second instance which supplies assorted vertical and horizontal lines (regularly referred to as "rules"):

egincenteregintabularc c c c hline Col1 & Col2 & Col2 & Col3 \ <0.5ex> hlinehline 1 & 6 & 87837 & 787 \ hline 2 & 7 & 78 & 5415 \ hline 3 & 545 & 778 & 7507 \ hline 4 & 545 & 18744 & 7560 \ hline 5 & 88 & 788 & 6344 \ <1ex> hlineendtabularendcenter
 Open this example in


Tables via resolved length

When formatting a table you might call for a resolved size either for each column or for the whole table. The following instance adds the range package to record preamble:

and also offers it to collection addressed column widths:

documentclassarticleusepackagearrayegindocumentegincenteregintabular hline cell1 dummy text dummy text dummy text& cell2 & cell3 \ hline cell1 dummy message dummy message dummy message & cell5 & cell6 \ hline cell7 & cell8 & cell9 \ hlineendtabularendcenterenddocument
 Open this instance in


In the tabular environment, the parameter m5em sets a size of 5em for initially column (1cm for the various other two) and centres the message in the middle of the cell. The aligning options are m for middle, p for peak and b for bottom. When making use of these parameters the text is instantly formatted to fit inside each cell.

If you don"t have to control the width of each cell, yet of the entire table and then evenly distribute the space within, use the tabularx package. See the instance below:

documentclassarticleusepackagetabularxegindocumentegintabularx0.8 extwidth >centeringarraybackslashX hline item 11 & item 12 & item 13 \ hline item 21 & item 22 & item 23 \hlineendtabularxenddocument
 Open this instance in


The environment tabularx is similar to tabular yet even more functional, To usage it, add the line usepackagetabularx to the record preamble. Notice that the environment opening statement is various, in the instance the table width is set to 0.8 extwidth, which is 80% of the document"s message width. You deserve to use any kind of of the LaTeX devices to collection this size.

The presettle inside braces | > aggedrightarraybackslashX | >centeringarraybackslashX | > aggedleftarraybackslashX | sets the alignment of each column: the initially one to left, the second one to facility and the 3rd one to best.

Combining rows and columns

Rows and columns can be linked to develop bigger table cells. The complying with example provides the multicolumn command also to merge numerous columns:

documentclassarticleusepackagemultirowegindocumentegintabularp3cm hline multicolumn4Country List \ hline Counattempt Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 Code&ISO numeric Code\ hline Afghanistan & AF &AFG& 004\ Aland Islands& AX & ALA &248\ Albania &AL & ALB& 008\ Algeria &DZ & DZA& 012\ Amerihave the right to Samoa& AS & ASM&016\ Andorra& ADVERTISEMENT & AND &020\ Angola& AO & AGO&024\ hlineendtabularenddocument
 Open this instance in


Let"s review each component of the command also multicolumn4Country List \:

4The number of columns to be combined: 4 in this situation.Delimiters and also alignment of the resulting cell: in this case the text will be centred and a vertical line will be drawn at each side of the cell.Counattempt ListText to be shown inside the cell.

To incorporate rows you should add the multirow package to your record preamble:

You can then usage the multirow command in your document:

documentclassarticleusepackagemultirowegindocumentegincenteregintabularc hlinecol1 & col2 & col3 \hlinemultirow34emMultiple row & cell2 & cell3 \ & cell5 & cell6 \ & cell8 & cell9 \ hlineendtabularendcenterenddocument
 Open this instance in


The multirow command takes 3 parameters; our instance uses the complying with settings:

the variety of rows to be combined: 3the width of the column: 4emthe content of the cell: Multiple row

Multi-page tables

If you have to insert an extremely long table, which takes up two or more pperiods in your document, use the longtable package. First, add the following line to your record preamble:

You can then usage the longtable environment, as displayed in the complying with example:

documentclassarticleusepackagelongtableegindocument eginlongtable c captionLong table caption.labellong\ hline multicolumn2Begin of Table\ hline Something & somepoint else\ hline endfirsthead hline multicolumn2Continuation of Table eflong\ hline Somepoint & something else\ hline endhead hline endfoot hline multicolumn2End of Table\ hlinehline endlastfoot Lots of lines & prefer this\ Lots of lines & like this\ Lots of lines & favor this\ Lots of lines & choose this\ Lots of lines & prefer this\ Lots of lines & like this\ Lots of lines & choose this\ Lots of lines & choose this\ ... Lots of lines & favor this\ endlongtable


 Open a longtable example in

The behaviour of longtable is comparable to the default tabular, but geneprices tables that have the right to be damaged by the standard LaTeX page-breaking algorithm. Tbelow are 4 longtable-specific elements:

endfirstheadEverything above this command also will appear at the start of the table, in the initially page.endheadWhatever you put prior to this command and also below endfirsthead will certainly be displayed at the top of the table in eexceptionally page other than the initially one.endfootComparable to endhead, what you put after endhead and also before this command will show up at the bottom of the table in eexceptionally page except the last one.endlastfootSimilar to endfirsthead. The elements after endfoot and also prior to this command also will certainly be shown at the bottom of the table but just in the last web page wbelow the table appears.

Positioning tables

Positioning a table is basic if they"re inside a float table environment.

documentclassarticleegindocumentBelow is a table positioned exactly here:egintablecentering egintabular hline Col1 & Col2 & Col2 & Col3 \ <0.5ex> hlinehline 1 & 6 & 87837 & 787 \ 2 & 7 & 78 & 5415 \ 3 & 545 & 778 & 7507 \ 4 & 545 & 18744 & 7560 \ 5 & 88 & 788 & 6344 \ <1ex> hline endtabularendtableenddocument
 Open this example in


The parameter h! passed to the table environment declaration creates that this table have to be placed right here, and override LaTeX defaults. The placing parameters that have the right to be passed-in include:

hWill place the table below about.tPosition the table at the top of the web page.bPosition the table at the bottom of the page.pPlaced the table in a distinct web page, for tables just.!Override internal LaTeX parameters.HPlace the table at this specific place, pretty much favor h!.

For additionally examples on table placing see the Positioning images and tables article.

In this instance there are a couple of even more commands:

centeringCentres the table relative to the float container aspect.<1ex>This adds extran area to the cell.

See more: Book Review: Good Faith Book Review, Book Review

Captions, labels and also references

Tables can be captioned, labelled and also referenced by implies of the table setting.

documentclassarticleegindocumentTable eftable:1 is an instance of a referenced LaTeX facet.egintablecenteringegintabular hline Col1 & Col2 & Col2 & Col3 \ <0.5ex> hlinehline 1 & 6 & 87837 & 787 \ 2 & 7 & 78 & 5415 \ 3 & 545 & 778 & 7507 \ 4 & 545 & 18744 & 7560 \ 5 & 88 & 788 & 6344 \ <1ex> hlineendtabularcaptionTable to test captions and also labels.labeltable:1endtableenddocument
 Open this instance in


Tright here are 3 essential commands in the example:

captionTable to test captions and labelsAs you may expect this command sets the inscription for the table. If you develop a list of tables this subtitle will certainly be provided tright here. You can area it above or listed below the table.labeltable:1If you have to recommendation the table within your record, set a label with this command. The label will certainly number the table and also, as soon as combined through the ef command, will certainly permit you to reference it. eftable:1This code will be substituted by the number equivalent to the referenced table.

List of tables

To produce a list of tables usage the listoftables command also. The inscription of each table will certainly be offered to generate this list. For languages supported by the babel package, the title "List of tables" will certainly be interpreted as necessary. See the article about International language assistance for even more details.

documentclassarticleegindocumentlistoftablesvspace5ptThe table eftable:1 is an instance of referenced LaTeX facets.egintablecenteringegintabular hline Col1 & Col2 & Col2 & Col3 \ <0.5ex> hlinehline 1 & 6 & 87837 & 787 \ 2 & 7 & 78 & 5415 \ 3 & 545 & 778 & 7507 \ 4 & 545 & 18744 & 7560 \ 5 & 88 & 788 & 6344 \ <1ex> hlineendtabularcaptionThis is the caption for the first table.labeltable:1endtableegintablecenteringegintabularc c c c hline Col1 & Col2 & Col2 & Col3 \ <0.5ex> hlinehline 4 & 545 & 18744 & 7560 \ 5 & 88 & 788 & 6344 \ <1ex> hlineendtabularcaptionThis is the caption for the second table.labeltable:2endtableenddocument
 Open this instance in


Changing the appearance of a table

Several table elements have the right to be modified to suit the requirements of your document. Below you will learn how to modify the line thickness, the line colour and the background colour of the cells in your table.

Line width and cell padding

The legibility of a table deserve to occasionally be improved by incrementing the column spacing and row stretch.

documentclassarticlesetlengtharrayrulewidth0.5mmsetlength abcolsep18pt enewcommandarraystretch1.5egindocumentegintabularp3cmhlinemulticolumn3Country List \hlineCounattempt Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \hlineAfghanistan & AF &AFG \Aland also Islands & AX & ALA \Albania &AL & ALB \Algeria &DZ & DZA \American Samoa & AS & ASM \Andorra & AD & AND \Angola & AO & AGO \hlineendtabularenddocument
 Open this example in


A description of the regulates is gave below:

setlengtharrayrulewidth0.5mmThis sets the thickness of the borders of the table. In the instance is 0.5mm but you have the right to use other units—watch the article Lengths in LaTeX for a complete list.setlength abcolsep18ptThe area in between the message and also the left/appropriate border of its containing cell is set to 18pt with this command also. Aacquire, you might use various other units if needed. enewcommandarraystretch1.5The elevation of each row is collection to 1.5 relative to its default height.

Colour alternating rows

You have the right to use alternating colours to the rows of your table by using the xcolor package through the table choice, as demonstrated in the complying with example:

documentclassarticleusepackagexcolorsetlengtharrayrulewidth0.5mmsetlength abcolsep18pt enewcommandarraystretch2.5egindocument{ owcolors3green!80!yellow!50green!70!yellow!40egintabular hlinemulticolumn3Country List \hlineCounattempt Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \hlineAfghanistan & AF &AFG \Aland also Islands & AX & ALA \Albania &AL & ALB \Algeria &DZ & DZA \Amerihave the right to Samoa & AS & ASM \Andorra & AD & AND \Angola & AO & AGO \hlineendtabularenddocument
 Open this instance in


Notice the braces ideal before the command

and after the tabular setting. The command also owcolors takes three parameters each passed inside braces:

the row to begin,the colour for odd rows andthe colour for also rows.

See the xshade package documentation (at the further reading section) for a list of available colours and also just how to produce your own. In the instance the colours green and also yellow are blended in different proparts.

For the command to work-related make certain to add


to the preamble of your LaTeX file.

Colouring a table (cells, rows, columns and lines)

All elements in a table can be customized to usage a details colour. Aobtain, this functionality is provided by xcolor so you must add


to the preamble. Below you have the right to check out an instance.

 Open this instance in


Below is a description about exactly how to change the colour of each element in the table:

Background colour of a cell. Use the command also cellcolor. You have the right to either enter the name directly inside the braces (red, gray, green and also so on) or pass a format parameter inside brackets (HTML in the example) and also then collection the preferred colour inside the braces utilizing the establimelted format.Background colour of a row. In this situation owshade will certainly accomplish that. The same observations about colour selection discussed in the two previous regulates are valid for this one.Background colour of a column. This one is a little bit tricky, yet the most basic way is to specify a new column type. The command
specify a column form dubbed s whose alignment is p, the column width is 3cm and also the colour is collection with HTML format to AAACED. This new column form is provided in the tabular setting.

Reference guide

A brief summary of parameters in the tabular environment.

Tables deserve to be produced using tabular setting.

egintabularcols table contentendtabularwbelow choices deserve to be:

pos : Vertical place. It have the right to assume the adhering to values:
tthe line at the peak is aligned with the message baseline
bthe line at the bottom is aligned with the text baseline
c or nonethe table is centred to the message baseline
cols : Defines the alignment and also the boundaries of each column. It can have the complying with values:
lleft-justified column
ccentred column
rright-justified column
p"width"paragraph column with message vertically aligned at the top
m"width"paragraph column via text vertically aligned in the middle (needs variety package)
b"width"paragraph column with text vertically aligned at the bottom (needs range package)
|vertical line
||double vertical line
*numformthe format develop is repetitive num times; for instance *3| is equal to |l|l|l|

To sepaprice in between cells and presenting brand-new lines usage the following commands:

&column separator
\start brand-new row (extra room may be specified after \ using square brackets, such as \<6pt>)
hlinehorizontal line between rows
ewlinebegin a brand-new line within a cell (in a paragraph column)
clinei-jpartial horizontal line start in column i and ending in column j

Additional reading

For more indevelopment see