Featured Book

LaTeX Beginners Guide

Who is online

In total there are 11 users online :: 0 registered, 0 hidden and 11 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 11 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Split Columns in a Table Topic is solved

Add tags Information and discussion about graphics, figures & tables in LaTeX documents.

Split Columns in a Table

Postby sw3quant on Tue Nov 27th, 2012

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

Code: Select all  •  Open in writeLaTeX
\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.! :oops:

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

Thank you!
Attachments
tab2-800.jpg
tab2-800.jpg (38.33 KiB) Viewed 1568 times
tab-800.jpg
tab-800.jpg (33.45 KiB) Viewed 1568 times
Last edited by cgnieder on Tue Nov 27th, 2012, edited 1 time in total.
Reason: scaled images so they can also be viewed on small screens
sw3quant
 
Posts: 70
Joined: Tue Nov 2nd, 2010

Re: Split Columns in a Table  Topic is solved

Postby cgnieder on Tue Nov 27th, 2012

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:

Code: Select all  •  Open in writeLaTeX
\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
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1670
Joined: Sat Apr 16th, 2011
Location: Germany


Return to Graphics, Figures & Tables

Who is online

Users browsing this forum: No registered users and 11 guests