1

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.

enter image description here

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

2 Answers 2

1

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 \addlinespace && \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 \addlinespace 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} 

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.

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

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} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.