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

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

Split Columns in a Table

Postby sw3quant » Tue Nov 27, 2012 2:55 pm

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

  1. \documentclass[final,authoryear,3p,times]{elsarticle}
  2. \usepackage{amssymb}
  3. \usepackage[T1]{fontenc}
  4. \usepackage{prettyref}
  5. \usepackage{url}
  6. \usepackage{amsmath}
  7. \usepackage{graphicx}
  8. \usepackage{amssymb}
  9. \usepackage{mathtools}
  10. \usepackage{xcolor}
  11. \usepackage{amsfonts}
  12. \usepackage{nicefrac}
  13. \usepackage{capt-of}
  14. \usepackage{float}
  15. \usepackage{xspace}
  16. \usepackage{verbatim}
  17. \usepackage{mathdots}
  18. \usepackage{bm}
  19. \usepackage{amsmath,amssymb}
  20. \usepackage{array}
  21. \newcommand{\head}[1]{\textbf{#1}}
  22. \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
  23. \usepackage{graphicx}
  24. \usepackage{caption}
  25. \usepackage{subcaption}
  26. \usepackage{rotating} %table in landscape
  27. \usepackage{color}
  28. \usepackage{array}
  29. \usepackage{longtable}
  30. \usepackage{calc}
  31. \usepackage{multirow}
  32. \usepackage{hhline}
  33. \usepackage{ifthen}
  34. \usepackage{lscape}
  35.  
  36.  
  37. \begin{document}
  38.  
  39.  
  40.  
  41. \begin{sidewaystable}
  42. \begin{center}
  43. \captionof{table}{\bf my Table}
  44. \footnotesize
  45. \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}|}
  46. \hline
  47. \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 (\%)} \\
  48. \hline \hline
  49. OR & X & X & X & X& X & X & X \\
  50. \hline
  51. SP & X & X & X & X& X & X & X \\
  52. \hline
  53. BF & X & X & X & X& X & X & X \\
  54. \hline
  55. PK & X & X & X & X& X & X & X \\
  56. \hline
  57. FB & X & X & X & X& X & X & X \\
  58. \hline
  59. CF & X & X & X & X& X & X & X \\
  60. \hline
  61. BS & X & X & X & X& X & X & X \\
  62. \hline
  63. DF & X & X & X & X& X & X & X \\
  64. \hline
  65. MP & X & X & X & X& X & X & X \\
  66. \hline
  67. PB & X & X & X & X& X & X & X \\
  68. \hline
  69. PS & X & X & X & X& X & X & X \\
  70. \hline
  71. Total & X [100.00] & X [100.00] & X & X [100.00] & X & X & X \\
  72. \hline
  73. \end{tabular}
  74. \label{hi}
  75. \end{center}
  76. \end{sidewaystable}
  77.  
  78.  
  79.  
  80.  
  81. \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 4852 times
tab-800.jpg
tab-800.jpg (33.45 KiB) Viewed 4852 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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Tue Nov 27, 2012 9:19 pm

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:

  1. \documentclass{article}
  2. \usepackage{array}
  3.  
  4. \begin{document}
  5.  
  6. \begin{tabular}{|c|c|c|}
  7. \hline
  8. \multicolumn{2}{|c|}{Head 1} & Head 2 \\
  9. \hline
  10. a & b & c \\
  11. \hline
  12. a & b & c \\
  13. \hline
  14. \end{tabular}
  15.  
  16. \end{document}


Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Link:
BBcode: Topic is solved[/url]" title="Click to select post's link in BBcode format" onclick="this.focus();this.select();" />
HTML: Topic is solved</a>" title="Click to select post's link in HTML format" onclick="this.focus();this.select();" />
Hide post links
Show post links


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 1 guest