Tag Archives: table

A tip for latex table, Create LaTex table online!

I found a pretty awesome tool that can create a LaTex table with an intuitive interface (like excel table). What all you need to do is filling a table and generate code. Of course copy and paste.

It also tells you which packages are required depending on your table design. My case, I need to use multirow package and it works like charm!.

Here is the link and enjoy.

http://www.tablesgenerator.com/#

Multi-column and multi-row cells in LaTeX tables

Source from http://texblog.org/2012/12/21/multi-column-and-multi-row-cells-in-latex-tables/

I always forget how to do this. If you have the same problem, here is a quick post for your bookmarks…

 

Basic commands
1
2
3
4
5
6
7
%multi-column
\multicolumn{number cols}{align}{text} % align: l,c,r
%multi-row
\usepackage{multirow}
\multirow{number rows}{width}{text}

Using * as width in the multirow command, the text argument’s natural width is used (multirow package documentation).

 

Multiple columns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\documentclass[11pt]{article}
\begin{document}
\begin{table}[ht]
\caption{Multi-column table}
\begin{center}
\begin{tabular}{cc}
    \hline
    \multicolumn{2}{c}{Multi-column}\\
    X&X\\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

multicol-table

 

Multiple rows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{cc}
    \hline
    \multirow{2}{*}{Multirow}&X\\
    &X\\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

multirow-table

 

Multiple rows and columns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[ht]
\caption{Multi-column and multi-row table}
\begin{center}
\begin{tabular}{ccc}
    \hline
    \multicolumn{2}{c}{\multirow{2}{*}{Multi-col-row}}&X\\
    \multicolumn{2}{c}{}&X\\
    \hline
    X&X&X\\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

multicol-row-table

The examples provided are very basic. Drop me a comment below in case you are having problems with a more complex table. Also, the color is just for illustration purposes and for simplicity reasons not part of the minimal working examples above. See here for how to color table columns or rows.

 

Partial horizontal line

Use \cline{columns} for a horizontal line spanning one or several table columns.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass[11pt]{article}
\begin{document}
\begin{table}[ht]
\caption{Partial horizontal line}
\begin{tabular}{ccc}
    \hline
    \multicolumn{2}{c}{Multi-column}&\\
    \cline{1-2}
    X&X&X\\
    X&X&X\\
    \hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

cline-table