7

I have created a table that is the width of my page, but when trying to center the text in the top row over the merged cell, the text is not centering with respect to the entire length of the cell.

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}

\begin{document}

\begin{table}[H]
\centering
\begin{tabular}{N|N|N|N|N|N|N|N|N|}
\cline{2-9}
\multicolumn{1}{N|}{\textbf{}} & \multicolumn{4}{G|}{\textbf{Emissions (Pre Catalytic Converter)}} & \multicolumn{4}{G|}{\textbf{Emissions (Post Catalytic Converter)}} \\  \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}

\end{document}

enter image description here

  • Welcome to TeX.SX! There is \usepackage{amsbsy} missing. And from some aesthetically point of view: Too much lines – user31729 Nov 2 '14 at 20:50
  • You want to combine 4 cells, each of them has 2 \tabcolsep space left and right of the cell content, so it's 6\tabcolsep in addition, I suppose – user31729 Nov 2 '14 at 21:00
8

In this case it is easier to just use two lines for the titles:

enter image description here

Notes:

  • You don't need to use \multicolumn{1}{N|}{\textbf{}}, just leaving it blank is sufficient.

However, I think you table would lok much better if you eliminated the vertical rules and used the booktabs package:

enter image description here

Code:

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}

\newcommand*{\boldsymbol}[1]{#1}

\begin{document}

\begin{table}[H]
\centering
\begin{tabular}{N|N|N|N|N|N|N|N|N|}
\cline{2-9}
     & \multicolumn{4}{c|}{\textbf{Emissions (Pre}} & \multicolumn{4}{c|}{\textbf{Emissions (Post}} \\  
     & \multicolumn{4}{c|}{\textbf{Catalytic Converter)}} & \multicolumn{4}{c|}{\textbf{Catalytic Converter)}} \\  \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}

\end{document}

Code: booktabs:

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\usepackage{booktabs}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}

\newcommand*{\boldsymbol}[1]{#1}

\begin{document}

\begin{table}[H]
\centering
\noindent
\begin{tabular}{N N N N N N N N N }\toprule
\multicolumn{1}{N }{\textbf{}} & \multicolumn{4}{c }{\textbf{Emissions (Pre}} & \multicolumn{4}{c }{\textbf{Emissions (Post}} \\  
\multicolumn{1}{c }{\textbf{}} & \multicolumn{4}{c }{\textbf{Catalytic Converter)}} & \multicolumn{4}{c }{\textbf{Catalytic Converter)}} \\ 
\cmidrule(lr){2-5}
\cmidrule(ll){6-9}
\multicolumn{1}{ N }{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ 
\cmidrule(lr){1-1}
\cmidrule(lr){2-5}
\cmidrule(ll){6-9}
\multicolumn{1}{ N }{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ 
\multicolumn{1}{ c }{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ 
\multicolumn{1}{ c }{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ 
\multicolumn{1}{ c }{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ 
\multicolumn{1}{ c }{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ 
\bottomrule
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}

\end{document}
  • add a \toprule and the 2nd table will be just perfect! :) – yo' Nov 2 '14 at 22:48
  • @tohecz: Good suggestion. Have added a \toprule. – Peter Grill Nov 4 '14 at 1:35
2

I used the code and 'improved' it a little bit.

There are 4 cells to be merged, meaning, this is not just 4 times the cell content width of the 'N' type.

|scs|scs|scs|scs|

Where s means \tabcolsep space (defaulting to 6pt and c the cell content, 'fixed' to 0.5in

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{amsbsy}%
\usepackage{graphicx}
\usepackage{array}
\usepackage{calc}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\bfseries\centering\arraybackslash}m{2in+6\tabcolsep}}

\begin{document}

\begin{table}[H]
\centering
\begin{tabular}{*{9}{N|}}
\cline{2-9}
\multicolumn{1}{N|}{} & \multicolumn{4}{G|}{Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G|}{Emissions (Post Catalytic Converter)} \tabularnewline  \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}

\end{document}

enter image description here

  • The lines are naughty ;-) – user31729 Nov 2 '14 at 21:07
2

While each column in N has been specified to have width 0.5in, four N-columns is not 2in wide. Each column is separated by an inter-column space/gap of \tabcolsep. And, when you use a vertical rule, it's actually 2\tabcolsep. As such, you can use a width of 2in+6\tabcolsep as the space for your G-column:

enter image description here

\documentclass{article}
\usepackage{graphicx,array,bm,booktabs}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{\dimexpr2in+6\tabcolsep}}

\begin{document}

\begin{tabular}{N*{8}{|N|}}
  \cline{2-9}
  \multicolumn{1}{N|}{} & \multicolumn{4}{G|}{\bfseries Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G|}{\bfseries Emissions (Post Catalytic Converter)} \\  \hline
  \multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
  \multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
  \multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
  \multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
  \multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
  \multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}

\bigskip

\begin{tabular}{c*{8}{N}}
  \toprule
  & \multicolumn{4}{G}{\bfseries Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G}{\bfseries Emissions (Post Catalytic Converter)} \\
  \cmidrule(lr){2-5}\cmidrule(lr){6-9}
  \multicolumn{1}{N}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & 
    \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\
  \midrule
    10    & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\
    30    & 0.78 & 13 & 555 & 14.2 &   -- & -- &  -- &   -- \\
    70    & 0.70 & 14 & 580 & 14.4 &   -- & -- &  -- &   -- \\
    90    & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\
  Neutral & 0.06 &  7 &  21 & 15.6 & 0.06 &  5 &  27 & 15.7 \\
  \bottomrule
\end{tabular}

\end{document}

I would use booktabs though...

  • This covers about the same as Chris' answer, except for the addition of booktabs. – Werner Nov 2 '14 at 21:07
  • I was only 1 minute faster ;-) – user31729 Nov 2 '14 at 21:09
2

Numeric tables usually are better typeset using siunitx. I prefer the rules provided by booktabs, but they aren't necessary: you can use vertical rules, if you prefer having a typographically disputable result. ;-)

\documentclass[draft,a4paper,twoside,12pt]{article}
\usepackage{siunitx,booktabs}

\newcommand{\splitcell}[1]{%
  \begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}

\begin{document}

\begin{table}
\centering
\begin{tabular}{
  S[table-format=2.0]
  S[table-format=1.2]
  S[table-format=2.0]
  S[table-format=3.0]
  S[table-format=2.1]
  S[table-format=1.2]
  S[table-format=2.0]
  S[table-format=3.0]
  S[table-format=2.1]
}
\toprule
 & \multicolumn{8}{c}{\bfseries Emissions} \\
\cmidrule(lr){2-9}
 & \multicolumn{4}{c}{\bfseries Pre Catalytic Converter}
 & \multicolumn{4}{c}{\bfseries Post Catalytic Converter} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
{\bfseries\splitcell{Dyno\\ Load\\ (\%)}}
 & {\bfseries\splitcell{CO \\ (\%)}}
 & {\bfseries\splitcell{HC \\ (ppm)}}
 & {\bfseries\splitcell{Nox \\ (ppm)}}
 & {\bfseries\boldmath\splitcell{CO$_2$ \\ (\%)}}
 & {\bfseries\splitcell{CO \\ (\%)}}
 & {\bfseries\splitcell{HC \\ (ppm)}}
 & {\bfseries\splitcell{Nox \\ (ppm)}}
 & {\bfseries\boldmath\splitcell{CO$_2$ \\ (\%)}} \\
\midrule
10        & 0.77 & 23 & 523 & 14.0 & 0.09 & 18   & 130  & 13.8 \\
30        & 0.78 & 13 & 555 & 14.2 & {--} & {--} & {--} & {--} \\
70        & 0.70 & 14 & 580 & 14.4 & {--} & {--} & {--} & {--} \\
90        & 0.74 & 15 & 630 & 14.5 & 0.70 & 15   & 618  & 14.6 \\
{Neutral} & 0.06 &  7 &  21 & 15.6 & 0.06 &  5   &  27  & 15.7 \\
\bottomrule
\end{tabular}
\caption{Some caption}
\label{2000Emissions}
\end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.