# Issues with table formatting and merging cells

I'm having issues formatting a table with certain merged cells. This is the code I have so far:

 \begin{table}[h]
\caption{Results}
\label{table_example}
\begin{center}
\begin{tabular}{ | *{9}{c|} }
\hline

& \multicolumn{3}{c|}{PMX} & \multicolumn{3}{c|}{CX} \\ \cline{4-9}
Number of Nodes in Graph & Heuristic Cost (NN) & Iterations & Average Cost & Cost Difference & Iterations & Average Cost & Cost Difference  \\ \hline
10   &230.60& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
50   &260.88& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
100   &349.65& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
500   & 442.81& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
1000   & 488.13 & 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
\end{tabular}
\end{center}
\end{table}


But this is what I get when what I want is for the PMX heading to be over the "Iterations", "Average Cost", "Cost Difference" and the CX heading to be over the same as well. I'm also not sure why it's missing a lot of the horizontal lines in the table.

• Welcome to TeX.SX! Please always post complete examples, which are compilable. Like this we do not have to guess your setup. – LaRiFaRi May 4 '16 at 8:22

I'm an absolute beginner here, but just playing around with your code I managed to get the following table:

    \begin{table}[h]
\caption{Results}
\label{table_example}
\centering
\begin{tabular}{ *{9}{c} }
\hline
&& \multicolumn{3}{c}{PMX} & \multicolumn{3}{c}{CX} \\
\cmidrule(lr){3-5}  \cmidrule(lr){6-8}
Nodes & HCost (NN) & It & Av Cost & Cost Diff & It & Av Cost & Cost Diff  \\ \hline
10   &230.60& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
50   &260.88& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
100   &349.65& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
500   & 442.81& 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
1000   & 488.13 & 0 & 0 & 0 & 0 & 0 & 0  \\ \hline
\end{tabular}
\end{table}


I am sure that someone can make it look more professional though.

I removed the vertical lines to make the table less cluttered and also added an extra Ampersand to centre PMX and CX over the columns you want. Plus a couple of \addlinespace to make it less compact. I've abbreviated your headings just so that I can see the complete table in my Latex -pdf editor.

• Good, but \begin{center} should be \centering (with possibly \medskip if the caption package is not used) and \end{center} should go. – egreg May 4 '16 at 7:37
• @egreg have updated to use \centering as suggested. – Steve Hodgkinson May 4 '16 at 8:04

You have defined 9 columns for your table and in the first row, you are using 7. But if I interpret your table correctly, it should be 8.

Here is how I would have done it:

% arara: pdflatex

\documentclass{IEEEtran}
\usepackage{blindtext}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}
\Blindtext
\begin{table*}
\caption{Results}\label{tab:table_example}
\centering
\begin{tabular}{%
S[table-format=4.0]
S[table-format=3.2]
*{6}{S[table-format=1.0]}
}
\toprule
& & \multicolumn{3}{c}{PMX} & \multicolumn{3}{c}{CX} \\
\cmidrule(lr){3-5}\cmidrule(lr){6-8}
{Number of Nodes in Graph} & {Heuristic Cost (NN)} & {Iterations} & {Average Cost} & {Cost Difference} & {Iterations} & {Average Cost} & {Cost Difference} \\
\midrule
10   & 230.60 & 0 & 0 & 0 & 0 & 0 & 0 \\
50   & 260.88 & 0 & 0 & 0 & 0 & 0 & 0 \\
100  & 349.65 & 0 & 0 & 0 & 0 & 0 & 0 \\
500  & 442.81 & 0 & 0 & 0 & 0 & 0 & 0 \\
1000 & 488.13 & 0 & 0 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\end{table*}
\Blindtext
\Blindtext
\end{document}