# Creating complex tables with multicolumn on different lines on latex

Can someone help me creating this table, I can't figure out how \multicolumn work. I can get to the first two rows of the table but no further. Please help.

Thanks

• Welcome to TeX.SX! Can you show us the code you have so far? You need to specify 18 columns in the table, using \multicolumn for the two first rows. – Torbjørn T. Mar 11 '14 at 16:14
• Also, a tip: You can use backticks  to mark your inline code as I did in my edit. – Adam Liter Mar 11 '14 at 16:28

With a tabular environment, you need to specify a column for each column in the most populated row. Then, where necessary, you can combine multiple columns together using the \multicolumn command.

The tabular should end up looking like this, with a total of 18 columns:

\documentclass[landscape]{article}
\usepackage[landscape]{geometry}
\begin{document}

\begin{tabular}{|*{18}{c|}}  % repeats {c|} 18 times
\hline
\multicolumn{9}{|c}{k-means clustering} & \multicolumn{9}{|c|}{Fuzzy c-means clustering} \\ \hline
\multicolumn{3}{|c}{50 clusters} & \multicolumn{3}{|c}{60 clusters} & \multicolumn{3}{|c}{70 clusters} &
\multicolumn{3}{|c}{50 clusters} & \multicolumn{3}{|c}{60 clusters} & \multicolumn{3}{|c|}{70 clusters} \\ \hline
CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD \\ \hline
& & & & & & & & & & & & & & & & &  \\ \hline
\end{tabular}

\end{document}


Edit:

To use this in (one example of) a typical two-column environment, you would want to use the \begin{table*} environment, which allows the table to float across the two columns. Note that it will necessarily have to be place on the next page from where you call it, so you might have to make the call to the table earlier in the code than where you want to actually refer to it. This example uses the IEEEtran class to illustrate:

\documentclass[]{IEEEtran}

\usepackage{lipsum} % Dummy Text

\begin{document}

\title{Title}
\maketitle

\section{A Section}
\lipsum

\begin{table*}
\caption{The Caption}
\centering
\begin{tabular}{|*{18}{c|}}
\hline
\multicolumn{9}{|c}{k-means clustering} & \multicolumn{9}{|c|}{Fuzzy c-means clustering} \\ \hline
\multicolumn{3}{|c}{50 clusters} & \multicolumn{3}{|c}{60 clusters} & \multicolumn{3}{|c}{70 clusters} &
\multicolumn{3}{|c}{50 clusters} & \multicolumn{3}{|c}{60 clusters} & \multicolumn{3}{|c|}{70 clusters} \\ \hline
CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD &CJ & HT & SVD \\ \hline
& & & & & & & & & & & & & & & & &  \\ \hline
\end{tabular}
\end{table*}

\section{A Second Section}
\lipsum

\end{document}


It appears as:

• Alternatively you can use \begin{tabular}{|*{18}{c|}} for a more compact column definition. – sodd Mar 11 '14 at 16:24
• Indeed, forgot about that. – cslstr Mar 11 '14 at 16:26
• Thanks a lot Mr.cslstr, one more question, I dont want to use the landscape mode to put this table. I want to put this on a two column paper such that the table spans the two columns. Using \begin{table*} will be sufficient or not for a long table like this? – user47754 Mar 11 '14 at 16:28
• See my edit. The important thing is the \begin{table*}` environment; it should work with any two-column format, so long as your font sizes don't expand the table so much that it goes outside the given margins. – cslstr Mar 11 '14 at 16:41
• Thanks for your quick reply. I am using the \documentclass{intech-journal}. The table is constrained to the left. I cannot add picture in the comment. Shared it on dropbox. Thanks. dropbox.com/s/wn8qa858htu5q7u/texquestion.jpg – user47754 Mar 11 '14 at 16:50