3

I have the following code for a table, but I can't figure out why 2 columns are wider:

\newcolumntype{C}{>{\centering\arraybackslash}p{2em}}
\begin{table}[h]
\centering
\caption[]{\footnotesize\textbf{The initial conditions for Honeybee embryos.}}
\label{table: initial target bee}
\resizebox{0.7\textwidth}{!}{%
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline 
\multirow{2}{*}{Genes} & \multicolumn{4}{c|}{Initial values in Regions} & \multicolumn{4}{c|}{Target values in Regions}\\
\cline{2-9}
& R1 & R2 & R3 & R4 & R1 & R2 & R3 & R4  \\
\hline
\emph{e}& 0.7 & 0.7 & 0.7 & 0.7 & 0 & 0 & 0 & 0 \\
\hline
\end{tabular}
}
\end{table}

Any suggestion please?

  • don't use [h] !! it usually generates a warning and latex changes it to [ht] but better to use [htp] to avoid teh float going to the end of the document. – David Carlisle Jul 25 '14 at 8:20
1

Something like this. You defined a newcolumntype C but used a small c in the column specifiers is the main error. Also, you might want to consider extend the arraystretch a bit via

\renewcommand*{\arraystretch}{1.5} % 1.5 can be adjusted to sue one's need.

enter image description here

Code

\documentclass{article}
\usepackage{array,graphicx,multirow}
\begin{document}
\newcolumntype{C}{>{\centering\arraybackslash}p{3em}}
\begin{table}[!h]
\centering
\caption[]{\footnotesize\textbf{The initial conditions for Honeybee embryos.}}
\label{table: initial target bee}
\resizebox{0.7\textwidth}{!}{%
\begin{tabular}{*{9}{|C}|}%|C|C|C|C|C|C|C|C|}
\hline 
\multirow{2}{*}{Genes} & \multicolumn{4}{c|}{Initial values in Regions} & \multicolumn{4}{c|}{Target values in Regions}\\
\cline{2-9}
& R1 & R2 & R3 & R4 & R1 & R2 & R3 & R4  \\\hline
\emph{e}& 0.7 & 0.7 & 0.7 & 0.7 & 0 & 0 & 0 & 0 \\\hline
\end{tabular}
}
\end{table}
\end{document}
  • Thanks, this works. I took that commend from somewhere else, but I didn't know how it works. – Maryam Jul 25 '14 at 6:55
  • @Maryam -- I see. Whenever you use a newcolumntype command to define a style for specific column(s), it is supposed to be used in the column specifier. – Jesse Jul 25 '14 at 7:03
1

This happens when the spanning \multicolumn is wider than the collective widths of the spanned columns. In those cases, the last column stretches to fill the wider \multicolumn. The way around this is to stretch the columns to make room (you've already defined a C-column for this):

enter image description here

\documentclass{article}
\usepackage{array,multirow,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}p{2em}}
\begin{document}

\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
  \hline
  \multirow{2}{*}{Genes} & \multicolumn{4}{c|}{Initial values in Regions} & \multicolumn{4}{c|}{Target values in Regions} \\
  \cline{2-9}
  & R1 & R2 & R3 & R4 & R1 & R2 & R3 & R4  \\
  \hline
  \emph{e} & 0.7 & 0.7 & 0.7 & 0.7 & 0 & 0 & 0 & 0 \\
  \hline
\end{tabular}

\bigskip

\begin{tabular}{c*{8}{C}}
  \toprule
  \smash{\raisebox{-.55\normalbaselineskip}{Genes}} & 
    \multicolumn{4}{c}{Initial values in Regions} & 
    \multicolumn{4}{c}{Target values in Regions} \\
  \cmidrule(lr){2-5}\cmidrule(lr){6-9}
           & R1  & R2  & R3  & R4  & R1  & R2  & R3  & R4 \\
  \midrule
  \emph{e} & 0.7 & 0.7 & 0.7 & 0.7 &  0  &  0  &  0  &  0 \\
  \bottomrule
\end{tabular}

\end{document}

The latter table doesn't require multirow, but it does require the awesome booktabs. Also note the short-hand column specification (see Shortcut to declare alignment of many columns in a table).

1

Typesetting good tables requires some hand work. For numeric tables I'd recommend siunitx, which provides amazing features with its S columns.

For the particular problem, increasing the \tabcolsep seems to give good results.

\documentclass{article}
\usepackage{siunitx,booktabs}
\begin{document}

\begin{table}

\addtolength{\tabcolsep}{6pt}
\begin{tabular}{
  @{}
  l
  *{4}{S[table-format=1.1]}
  *{4}{S[table-format=1.0]}
  @{}
}
\toprule
Genes &
  \multicolumn{4}{c}{Initial values in Regions} &
  \multicolumn{4}{c}{Target values in Regions} \\
\cmidrule(lr){2-5}
\cmidrule(l){6-9} % no trimming at the right
         & {R1} & {R2} & {R3} & {R4} & {R1} & {R2} & {R3} & {R4} \\
\midrule
\emph{e} & 0.7  & 0.7  & 0.7  & 0.7  & 0    & 0    & 0    & 0    \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

The change to the parameter will not propagate, because it's in a table environnment.

There is also no need to lower “Genes”: it's a heading at the same level as the other first level headings. The first column should be left aligned.

In the specification for the S columns, you tell the number of digits in the integer and in the decimal part.

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.