3

I want to create this kind of table with 3 large columns and at one point the column is divided to two smaller columns. Please note that the column not divided in the whole space.

How can create the table with custom column sizes inside the larger columns?

|------------------------------------------------------------| | | A | Most Mon | -------------------------------------------------------------| | Methods | Time [s] | RunCount | Time [s] | RunCount | |----------------|---------------------|---------------------| | C | | | 4 | 1 | | D | | | 5 | 2 | | E | | | 6 | 3 | -------------------------------------------------------------| 
0

2 Answers 2

7

Actually, it's the other way round; initially you declare 5 columns and, in the first row, using \multicolumn you span some cells to occupy to of them.

In the following example, the packages siunitx and booktabs were used to improve the table formatting:

\documentclass{article} \usepackage{siunitx} \usepackage{booktabs} \begin{document} \noindent\begin{tabular}{lSSSS} \toprule & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{Most Mon} \\ \cmidrule(r){2-3}\cmidrule(l){4-5} Methods & {Time [\si{\second}]} & {RunCount} & {Time [\si{\second}]} & {RunCount} \\ \midrule C & 12.3 & 5 & 34.6 & 7 \\ D & 1.35 & 5 & 4.93 & 7 \\ \bottomrule \end{tabular} \end{document} 

enter image description here

Of course, instead of S you could use any other column type (and deal with possible alignments in other ways) such as c, l, r, or p{<length>}.

In a comment it has been requested to produce the table with the vertical rules; here it is:

\documentclass{article} \usepackage{siunitx} \begin{document} \noindent\begin{tabular}{| l | S | S | S | S |} \cline{2-5} \multicolumn{1}{c|}{}& \multicolumn{2}{c|}{A} & \multicolumn{2}{c|}{Most Mon} \\ \hline Methods & {Time [\si{\second}]} & {RunCount} & {Time [\si{\second}]} & {RunCount} \\ \hline C & 12.3 & 5 & 34.6 & 7 \\ D & 1.35 & 5 & 4.93 & 7 \\ \hline \end{tabular} \end{document} 

enter image description here

2
  • This is missing the vertical lines, I got odd looking lines when I tried to add them. How can you add them? Commented Feb 15, 2014 at 13:52
  • 1
    @hhh Yes, the idea behind booktabs is not to use vertical rules. If you want to add them, use the standard LaTeX commands for tables; please see my updated answer. Commented Feb 15, 2014 at 14:01
3

Another attempt where an M column type for centering is defined and the number alignment is used in the cell via \tablenum[format]{num}.

enter image description here

Code

\documentclass[border=10pt]{standalone} \usepackage{array,siunitx} \begin{document} \newcolumntype{M}{>{\centering\arraybackslash}m{2cm}} %\begin{table}%[!htb] %\centering %\caption{The caption} \begin{tabular}{*{6}{|M}|} \hline \multicolumn{2}{|c|}{} & \multicolumn{2}{c}{A} & \multicolumn{2}{|c|}{Most Mon}\\ \hline \multicolumn{2}{|c|}{Methods} & Time [s] & RunCount &Time [s] & RunCount\\ \hline \multicolumn{2}{|c|}{C} &\tablenum[table-format=4.4]{3.5} & &4 & 1 \\ \multicolumn{2}{|c|}{D} &\tablenum{3.75} & &5 & 2 \\ \multicolumn{2}{|c|}{E} &\tablenum{23.6} & &6 & 3 \\ \hline \end{tabular} %\end{table} 

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.