LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Split Columns in a Table Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Split Columns in a Table

I have a table which I construct as following (This is MWE):

\documentclass[final,authoryear,3p,times]{elsarticle}\usepackage{amssymb}\usepackage[T1]{fontenc}\usepackage{prettyref}\usepackage{url}\usepackage{amsmath}\usepackage{graphicx}\usepackage{amssymb}\usepackage{mathtools}\usepackage{xcolor}\usepackage{amsfonts}\usepackage{nicefrac}\usepackage{capt-of}\usepackage{float}\usepackage{xspace}\usepackage{verbatim}\usepackage{mathdots}\usepackage{bm}\usepackage{amsmath,amssymb}\usepackage{array}\newcommand{\head}[1]{\textbf{#1}}\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}\usepackage{graphicx}\usepackage{caption}\usepackage{subcaption}\usepackage{rotating} %table in landscape\usepackage{color}\usepackage{array}\usepackage{longtable}\usepackage{calc}\usepackage{multirow}\usepackage{hhline}\usepackage{ifthen}\usepackage{lscape}  \begin{document}   \begin{sidewaystable}\begin{center}\captionof{table}{\bf my Table}\footnotesize\begin{tabular}{|C{0.6cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|C{2.0cm}|}   \hline\textbf{Code}   & \head{Number of ohh (\# [\%])} &  \head{AHHH (P [\%])} &  \head{Mean WAAA (lots)} & \head{Number of PLOP (\# [\%])} &  \head{OHH Volume (G [\%])} & \head{Mean WAA (Y)} & \head{Fleeting Z (\%)} \\   \hline \hline   OR & X & X & X & X&  X & X  & X \\   \hline   SP & X & X & X & X&  X & X & X  \\   \hline   BF & X & X & X & X&  X & X & X  \\   \hline   PK & X & X & X & X&  X & X & X  \\   \hline   FB & X & X & X & X&  X & X & X  \\   \hline   CF & X & X & X & X&  X & X & X  \\   \hline   BS & X & X & X & X&  X & X & X  \\   \hline   DF & X & X & X & X&  X & X & X \\   \hline   MP & X & X & X & X&  X & X & X  \\   \hline   PB & X & X & X & X&  X & X & X \\   \hline   PS & X & X & X & X&  X & X & X  \\   \hline   Total & X [100.00] & X [100.00] & X & X [100.00] &  X & X & X \\   \hline\end{tabular}\label{hi}\end{center}\end{sidewaystable}    \end{document}

and it gives me a nice looking table, as per the attached pic. great.

However I now wish to split each col into two. I will use the first col as an example.

I wish the top row "Number of Ohh ()" to span two cols. Then a new row underneath that, which is 2 cells wide, with the names col A and colB.

Hence each existing col header cell is merged (in EXCEL language) and becomes the merged header for 2 new cols : col A and col B.

I have posted an attempt to show this.!

Having looked around on the web, I havent a clue how to do this. Can anyone help?

Thank you!
Attachments
tab2-800.jpg (38.33 KiB) Viewed 5865 times
tab-800.jpg (33.45 KiB) Viewed 5865 times
Last edited by cgnieder on Tue Nov 27, 2012 9:11 pm, edited 1 time in total.
Reason: scaled images so they can also be viewed on small screens

cgnieder
Site Moderator
Posts: 1973
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
I guess you're looking for \multicolumn{<num of cols>}{<col specs>}{<cell contents>} that can be used to merge <num of cols> cells into one cell. Here is an example:

\documentclass{article}\usepackage{array} \begin{document} \begin{tabular}{|c|c|c|}  \hline   \multicolumn{2}{|c|}{Head 1} & Head 2 \\  \hline   a & b & c \\  \hline   a & b & c \\  \hline\end{tabular} \end{document}

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim