1

For the table in the MWE shown below I need to use the options below:

  • Make rows of alternating colors
  • Make horizontal lines from second to fifth column
  • Give a single color to the merged cells containing the text (Multiples) & (Submultiples)

I cannot get those 2 options to work at the same time.

  • For alternating row colors I am using \rowcolors{2}{white}{gray!25}
  • For controlling the extension of the horizontal lines I am trying to use one of the 2 commands:

    \hhline{~----}

    \cmidrule{2-5}

Both commands cause the alternating row colors to disapear. However, the (hhline) command results in an additional issue, which is the appearence of white spaces in the place of the empty of horizontal lines.


\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry} 

\usepackage[bidi=basic,layout=lists.tabular]{babel}
\babelfont[english]{rm}{Times New Roman}

\usepackage[table]{xcolor}
\usepackage{tabu,multirow} 
\usepackage{array} 
\newcolumntype{?}[1]{!{\vrule width #1}} 
\usepackage{booktabs}
\setlength{\belowrulesep}{0pt}
\setlength{\belowbottomsep}{0pt}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\abovetopsep}{0pt}
\usepackage{makecell} 
\usepackage{boldline} 
\usepackage{hhline}
\usepackage{rotating}

\begin{document}
\begin{table}[!tb]
\setlength\arrayrulewidth{1pt}
\begin{center}
\caption{Common multiples and submultiples of SI Units}
\label{Tab:SI}
\rowcolors{2}{white}{gray!25}
\begin{tabular}{?{1mm}c|c|c|c|>{\centering\arraybackslash}m{3cm}?{1mm}}
\rowcolor{white}
\toprule[1mm]
\multicolumn{2}{?{1mm}c|}{\textbf{Multiplication factor}} &\textbf{Exponential Form} & \textbf{Multiple Prefix} & \textbf{Multiple Abbreviation / SI SYmbol} \\
\midrule[1.5pt]
 & 1 000 000 000 000 000 000 & $10^{18}$ & exa & E \\
\hhline{~----}
 & 1 000 000 000 000 000 & $10^{15}$ & peta & P \\
\hhline{~----}
 & 1 000 000 000 000 & $10^{12}$ & tera & T \\
\hhline{~----}
 & 1 000 000 000 & $10^{9}$ & giga & G \\
\hhline{~----}
 & 1 000 000 & $10^{6}$ & mega & M \\
\cmidrule{2-5}
 & 1 000 & $10^{3}$ & kilo & k \\
\cmidrule{2-5}
 & 1 00 & $10^{2}$ & hecto & h \\
\cmidrule{2-5}
\multirow{-8}{*}{\rotatebox[origin=c]{90}{\textbf{Multiples}}} & 1 0 & $10^{1}$ & deka & da \\
\midrule[1.5pt]
 & 0.1 & $10^{-1}$ & deci & d \\
\hline
 & 0.01 & $10^{-2}$ & centi & c \\
\hline
 & 0.001 & $10^{-3}$ & milli & m \\
\hline
 & 0.000 001 & $10^{-6}$ & micro & μ \\
\hline
 & 0.000 000 001 & $10^{-9}$ & nano & n \\
\hline
 & 0.000 000 000 001 & $10^{-12}$ & pico & p \\
\hline
 & 0.000 000 000 000 001 & $10^{-15}$ & femto & f \\
\hline
\multirow{-8}{*}{\rotatebox[origin=c]{90}{\textbf{submultiples}}} & 0.000 000 000 000 000 001 & $10^{-18}$ & atto & a \\
\bottomrule[1mm]
\end{tabular}
\end{center}
\end{table}
\end{document}

Output

2 Answers 2

1

For horizontal lines I would rather use Xhline defined in makecell package. They haven't problems with coloring rows as it has hhline rules. Also I would remove all \cline since then table (at least to my opinion) become more nice.

Edit: Unfortunately any kind of \cline cause your problem. So far temporary solution is not to use them, and (then) ask colortbl package author, how to fix this bug/misfeatures.

enter image description here

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}

\usepackage[table]{xcolor}
\newcommand\ccw{\cellcolor{white}}
\usepackage{array, booktabs, makecell, multirow}
\newcolumntype{?}[1]{!{\vrule width #1}}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\usepackage{boldline}
%\usepackage{hhline}
\usepackage{rotating}

\begin{document}
    \begin{table}[!tb]
    \centering
    \renewcommand\arraystretch{1.1}
\caption{Common multiples and submultiples of SI Units}
\label{Tab:SI}
    \rowcolors{2}{white}{gray!10}
\begin{tabular}{?{1pt}c|c|c|c|>{\centering\arraybackslash}m{3cm}?{1pt}}
    \Xhline{1pt}
    &   \thead{Multiplication\\ factor}   
        &   \thead{Exponential\\ Form} 
            &   \thead{Multiple\\ Prefix} 
                &   \textbf{Multiple Abbreviation / SI SYmbol} \\
    \Xhline{0.5pt}
\ccw
    & 1 000 000 000 000 000 000 & $10^{18}$ & exa & E \\
    & 1 000 000 000 000 000 & $10^{15}$ & peta & P \\
\ccw
    & 1 000 000 000 000 & $10^{12}$ & tera & T \\
    & 1 000 000 000 & $10^{9}$ & giga & G \\
\ccw
    & 1 000 000 & $10^{6}$ & mega & M \\
    & 1 000 & $10^{3}$ & kilo & k \\
\ccw
    & 1 00 & $10^{2}$ & hecto & h \\
\multirow{-8}{*}{\rotatebox[origin=c]{90}{\textbf{Multiples}}}
    & 1 0 & $10^{1}$ & deka & da \\
    \Xhline{0.5pt}
\ccw
    & 0.1 & $10^{-1}$ & deci & d \\
    & 0.01 & $10^{-2}$ & centi & c \\
\ccw
    & 0.001 & $10^{-3}$ & milli & m \\
    & 0.000 001 & $10^{-6}$ & micro & μ \\
\ccw
    & 0.000 000 001 & $10^{-9}$ & nano & n \\
    & 0.000 000 000 001 & $10^{-12}$ & pico & p \\
\ccw
& 0.000 000 000 000 001 & $10^{-15}$ & femto & f \\
\multirow{-8}{*}{\rotatebox[origin=c]{90}{\textbf{Multiples}}}
    & 0.000 000 000 000 000 001 & $10^{-18}$ & atto & a \\
    \Xhline{1pt}
\end{tabular}
    \end{table}
\end{document}
8
  • @ Zarko, but you removed the middle horizontal lines, and alternating row colors continued till the merged cells (Multiples & Submultiples)
    – Silva
    Oct 23, 2019 at 1:31
  • @Silva, I said how I would make your table. Dropped \clines you can return with \Xcline{2-5}{1pt}. See edited answer
    – Zarko
    Oct 23, 2019 at 2:16
  • the command Xhline causes no issues with alternating row colors, HOWEVER, THE COMMAND Xcline {2-5}{1.5pt} CAUSES A CONFLICT WITH ALTERNATING COLORS, all rows become same color
    – Silva
    Oct 23, 2019 at 11:05
  • @Silva, I test my MWE also with Xcline. It works without any problem. In test I use recent MikTeX. If you can not obtain desired result, than you have outdated LaTeX installation. Upgrade it. I will extend answer with showing, that Xcline works.
    – Zarko
    Oct 23, 2019 at 11:11
  • @Silva, you are right. It seems that should live without \Xcline or \cline or `hhline between rows. With out them your table is -- to my opinion -- look nicer.
    – Zarko
    Oct 23, 2019 at 11:22
0

Here is a way to do that table with {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. For the rows, you give the number of logical rows (and not the number of physical lines as with \multicolumn).

With the key hvlines, all the rules are drawn, excepted in the blocks (constructed by \Block).

I have drawn the main frame, with heavy rules, by a Tikz instruction after the construction of the main array:

\tikz \draw [thick] (1-|1) rectangle (last-|last) ;

\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}
\usepackage{nicematrix,tikz}

\begin{document}
\begin{table}[!tb]
\centering
\renewcommand\arraystretch{1.1}
\caption{Common multiples and submultiples of SI Units}
\label{Tab:SI}
    
\begin{NiceTabular}{>{\bfseries}c|c|c|c|c}[hvlines,color-inside]
\RowStyle[cell-space-limits=3pt]{\bfseries}
    &   \Block{}{Multiplication\\ factor}   
        &   \Block{}{Exponential\\ Form} 
            &   \Block{}{Multiple\\ Prefix} 
                &   \Block{}{Multiple\\ Abbreviation\\ / SI SYmbol} \\
\rowcolors{gray!10}{}[cols=2-]
\Block{8-1}{\rotate Multiples }
    & 1 000 000 000 000 000 000 & $10^{18}$ & exa & E \\
    & 1 000 000 000 000 000 & $10^{15}$ & peta & P \\
    & 1 000 000 000 000 & $10^{12}$ & tera & T \\
    & 1 000 000 000 & $10^{9}$ & giga & G \\
    & 1 000 000 & $10^{6}$ & mega & M \\
    & 1 000 & $10^{3}$ & kilo & k \\
    & 1 00 & $10^{2}$ & hecto & h \\
    & 1 0 & $10^{1}$ & deka & da \\
\Block{8-1}{\rotate Multiples}
    & 0.1 & $10^{-1}$ & deci & d \\
    & 0.01 & $10^{-2}$ & centi & c \\
    & 0.001 & $10^{-3}$ & milli & m \\
    & 0.000 001 & $10^{-6}$ & micro & \textmu \\
    & 0.000 000 001 & $10^{-9}$ & nano & n \\
    & 0.000 000 000 001 & $10^{-12}$ & pico & p \\
    & 0.000 000 000 000 001 & $10^{-15}$ & femto & f \\
    & 0.000 000 000 000 000 001 & $10^{-18}$ & atto & a \\
\CodeAfter \tikz \draw [thick] (1-|1) rectangle (last-|last) ; 
\end{NiceTabular}
\end{table}
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .