3

As you can see in the example below, the partial horizontal lines, for which I have used "\cline", are overwritten by the gray shading with "\cellcolor".

I have seen several proposals to get around this problem but none have been satisfactory. My last attempt with "\hhline" cuts the vertical lines by a white stripe ...

Nor have I gotten the line that should close the table on the right. In this case, I think the problem is caused by the "\multirow" command.

enter image description here

\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage{amsmath, amsfonts,amssymb,epsfig,amstext,amsthm,mathpazo}
\usepackage{array}
\usepackage{xcolor}
\usepackage{colortbl} %Color en celdas
\usepackage{nicematrix} %Dibuja las lineas \hline de las tablas después del coloreado de celdas
\usepackage{float}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{booktabs} %\cmidrule[espesor](recorte) {cola-colb}.  Parámetro recorte: especifica si la línea se recorta a la izquierda y/o a la derecha y en que proporción. Parámetros cola y colb: indican de qué columna a qué columna va la línea.

\begin{document}
    \extrarowheight = -0.25ex %Ajusta espacio superior entre filas para centrado vertical
    \renewcommand{\arraystretch}{2} %Ajusta alto de filas
    \renewcommand {\tabcolsep}{6pt} %Ajusta espacio interior entre columnas
    \renewcommand{\arrayrulewidth}{2pt} %Ajusta el grueso de línea
\begin{center}
    \begin{tabular} {| w{c}{1.4em} | *{12}{|w{c}{1.4em}}|} %Celdas de ancho fijo con alineación horizontal y vertical
        \hline
        \centering      
        {\large $ \lambda $} & \multicolumn{12}{c}{{\large \textbf{Generator Pairs $ (\beta_i, \gamma_i) $}}} \vline\\
        \hline  \hline 
        \multirow{2}{*} 
        {\large \textbf{1}} & \cellcolor[gray]{0.9} $ \beta_6 $ & \cellcolor[gray]{0.9} $ \beta_5 $ & \cellcolor[gray]{0.9} $ \beta_4 $ & \cellcolor[gray]{0.9} $ \beta_3 $ & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ & \cellcolor[gray]{0.9} $ \gamma_3 $ & \cellcolor[gray]{0.9} $ \gamma_4 $ & \cellcolor[gray]{0.9} $ \gamma_5 $ & \cellcolor[gray]{0.9} $ \gamma_6 $  \\ 
        \cline{2-13}
        & 1 & 2 & 3 & 6 & 7 & 9 & 14 & 18 & 21 & 42 & 63 & 126 \\ 
        \hline
        \multirow{2}{*}     
        {\large \textbf{2}} & \cellcolor[gray]{0.9} $ \beta_3 $ & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ & \cellcolor[gray]{0.9} $ \gamma_3 $ \multirow{2}{*}{} \\ 
        \cline{2-7}
        \multirow{2}{*}
        & 1 & 3 & 7 & 9 & 21 & 63 \\ 
        \cline{1-9}
        \multirow{2}{*}     
        {\large \textbf{3}} & \cellcolor[gray]{0.9} $ \beta_4 $ & \cellcolor[gray]{0.9} $ \beta_3 $ & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ & \cellcolor[gray]{0.9} $ \gamma_3 $ & \cellcolor[gray]{0.9} $ \gamma_4 $ \multirow{2}{*}{} \\ 
        \cline{2-9}
        & 1 & 2 & 3 & 6 & 7 & 14 & 21 & 42 \\ 
        \cline{1-9}
        \multirow{2}{*}     
        {\large \textbf{6}} & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ \multirow{2}{*}{} \\ 
        \cline{2-5}      
        \multirow{2}{*}
        & 1 & 3 & 7 & 21 \\ 
        \cline{1-7}
        \multirow{2}{*}     
        {\large \textbf{7}} & \cellcolor[gray]{0.9} $ \beta_3 $ & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ & \cellcolor[gray]{0.9} $ \gamma_3 $ \multirow{2}{*}{} \\ 
        \cline{2-7}      
        \multirow{2}{*}
        & 1 & 2 & 3 & 6 & 9 & 18 \\ 
        \cline{1-7}
        \multirow{2}{*}     
        {\large {\textbf{14}}} & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \boxdot^2 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ \multirow{2}{*}{} \\ 
        \cline{2-4}      
        \multirow{2}{*}
        & 1 & 3 & 9 \\ 
        \cline{1-5}
        \multirow{2}{*}     
        {\large {\textbf{21}}} & \cellcolor[gray]{0.9} $ \beta_2 $ & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ & \cellcolor[gray]{0.9} $ \gamma_2 $ \multirow{2}{*}{} \\ 
        %\cline{2-5}    
        \hhline{~ *{4}{-}}   
        & 1 & 2 & 3 & 6 \\ 
        %\cline{1-5}
        \hhline{*{5}{-}}
        \multirow{2}{*}
        {\large {\textbf{42}}} & \cellcolor[gray]{0.9} $ \beta_1 $ & \cellcolor[gray]{0.9} $ \gamma_1 $ \multirow{2}{*}{} \\ 
        \cline{2-3}      
        & 1 & 3\\
        \hline          
    \end{tabular}
\end{center}
\end{document}
4
  • 3
    the colortbl package documentation explicitly states that \cline does not work with that package. that really is not fixable, sorry. Mar 27 at 22:48
  • are you sure you want negative \extrarowheight = -0.25ex I have never seen that set negative and I can't see how it can produce reasonable results, especially if you have coloured rows. Mar 27 at 22:57
  • David, \extrarowheight = -0.25ex is an adjustment so that the text is perfectly centered vertically (I had noticed that it was slightly below the center of the cell). Mar 27 at 23:13
1

Here is what you can do with nicematrix.

\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage{amsmath, amssymb,graphicx,amstext,amsthm,mathpazo}
\usepackage{xcolor}
\usepackage{nicematrix,tikz} 
\usepackage{float}
\usepackage{booktabs}

\begin{document}
\extrarowheight = -0.25ex
\renewcommand{\arraystretch}{2}
\begin{center}
\setlength{\tabcolsep}{4pt}
\newcolumntype{I}{!{\vrule}}
\begin{NiceTabular}{|>{\large\bfseries}cc*{11}{Ic}I}[columns-width=1.5em]
\CodeBefore
  \rectanglecolor[gray]{0.9}{2-2}{2-13}
  \rectanglecolor[gray]{0.9}{4-2}{4-7}
  \rectanglecolor[gray]{0.9}{6-2}{6-9}
  \rectanglecolor[gray]{0.9}{8-2}{8-5}
  \rectanglecolor[gray]{0.9}{10-2}{10-7}
  \rectanglecolor[gray]{0.9}{12-2}{12-4}
  \rectanglecolor[gray]{0.9}{14-2}{14-5}
  \rectanglecolor[gray]{0.9}{16-2}{16-3}
\Body
    \hline
    $\lambda$ \rlap{\hspace*{2.8cm}Generator Pairs \boldmath $(\beta_i,\gamma_i)$} \\ 
    \Block{2-1}{1} 
    & $\beta_6$ & $\beta_5$ & $\beta_4$ & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ & $\gamma_4$ & $\gamma_5$ & $\gamma_6$ \\ \cline{2-13}
    & 1 & 2 & 3 & 6 & 7 & 9 & 14 & 18 & 21 & 42 & 63 & 126 \\ \cline{1-13}
    \Block{2-1}{2}
    & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ \\ \cline{2-7}
    & 1 & 3 & 7 & 9 & 21 & 63 \\ \cline{1-9}
    \Block{2-1}{3}
    & $\beta_4$ & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ & $\gamma_4$ \\ \cline{2-9}
    & 1 & 2 & 3 & 6 & 7 & 14 & 21 & 42 \\ \cline{1-9}
    \Block{2-1}{6}
    & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ \\ \cline{2-5}
    & 1 & 3 & 7 & 21 \\ \cline{1-7}
    \Block{2-1}{7} 
    & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ \\ \cline{2-7}
    & 1 & 2 & 3 & 6 & 9 & 18 \\ \cline{1-7}
    \Block{2-1}{14} 
    & $\beta_1$ & $\boxdot^2$ & $\gamma_1$ \\ \cline{2-4}
    & 1 & 3 & 9 \\ \cline{1-5}
    \Block{2-1}{21}
    & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ \\ \cline{2-5}
    & 1 & 2 & 3 & 6 \\ \cline{1-5}
    \Block{2-1}{42}
    & $\beta_1$ & $\gamma_1$ \\ \cline{2-3}
    & 1 & 3 \\ \cline{1-3}
\CodeAfter
   \tikz \draw (1-|last) -- (2-|last) ;
   \tikz \draw [double] (2-|1) -- (2-|last) ;
   \tikz \draw [double] (1-|2) -- (last-|2) ;
\end{NiceTabular}
\end{center}

\end{document} 

Output of the above code

4
  • Thanks again Bernard. It is obvious that I am starting with Latex, but I try to translate the designs I had made in Word and other programs into Latex, avoiding as much as possible to include them as an .eps image. Fortunately, I have found this site invaluable. It never ceases to amaze me how quickly solutions are obtained to any problem that arises. As for all the, for me, new information about Latex, I will need some time to learn how to use it, rather than memorize it. Mar 28 at 16:47
  • The first of the solutions you have given me has worked perfectly for me when including it in the rest of the code (except that I had to change \setlength {\tabcolsep} {4pt} by \renewcommand {\tabcolsep} {4pt}) although I had I have to carry out a systematic inspection of all the packages that I have loaded until detecting which one was incompatible (% \usepackage [usenames] {color}). Due to lack of theoretical knowledge of the packages, I have been loading them as I have needed them, but now I have many and that favors the possibilities of incompatibilities. Mar 28 at 16:49
  • Your second proposal, more optimized in code and with a more aesthetic result than mine, gives me errors and at the moment I will not be able to use it, for the reasons already mentioned of incompatibility between packages and, perhaps, also by commands that I have defined. Best regards from Spain. Mar 28 at 16:50
  • Oh sorry, F. Pantigny; I did not realize that it was you, none other than the author of the NiceMatrix package, who was showing me how to apply it. Many thanks. Excellent solution!. Best regards from Spain. Mar 28 at 16:58
4

Here is a code that works. Some remarks: I didn't load colortbl, as xcolor with the [table] option loads it. Furthermore, I replaced all \cellcolor commands with a single \rowcolor at the beginning of the rows. Also,epsfig is obsolete and should be replaced with graphicx. Finally, I had to define a smaller column width, as the table did not fit between the margins.

\documentclass[a4paper,14pt,twoside,reqno]{extbook}
\usepackage{amsmath, amssymb,graphicx,amstext,amsthm,mathpazo}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage{nicematrix} %Dibuja las lineas \hline de las tablas después del coloreado de celdas
\usepackage{float}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{booktabs} %\cmidrule[espesor](recorte) {cola-colb}. Parámetro recorte: especifica si la línea se recorta a la izquierda y/o a la derecha y en que proporción. Parámetros cola y colb: indican de qué columna a qué columna va la línea.

\begin{document}
\extrarowheight = -0.25ex %Ajusta espacio superior entre filas para centrado vertical
\renewcommand{\arraystretch}{2} %Ajusta alto de filas
\renewcommand{\arrayrulewidth}{2pt} %Ajusta el grueso de línea
\begin{center}
\setlength{\tabcolsep}{4pt}
\begin{tabular} {| w{c}{1.25em} | *{12}{|w{c}{1.25em}}|} %Celdas de ancho fijo con alineación horizontal y vertical
    \hline
    {\large\boldmath $ \lambda $} & \multicolumn{12}{c}{{\large \textbf{Generator Pairs \boldmath$ (\beta_i, \gamma_i) $}}} \vline\\
    \hline \hline
    \rowcolor[gray]{0.9} \multirow{2}{*}{\cellcolor{white}\large \textbf{1}}%
    & $\beta_6$ & $\beta_5$ & $\beta_4$ & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ & $\gamma_4$ & $\gamma_5$ & $\gamma_6$ \\
    \cline{2-13}
    & 1 & 2 & 3 & 6 & 7 & 9 & 14 & 18 & 21 & 42 & 63 & 126 \\
    \hhline{|-||*{12}{-}}
    \rowcolor[gray]{0.9}\multirow{2}{*}{\cellcolor{white}\large \textbf{2}}%
    & $\beta_3$ & $\beta_2$ & $\beta_1$ & $\gamma_1$ & $\gamma_2$ & $\gamma_3$ \\
    \cline{2-7}
    & 1 & 3 & 7 & 9 & 21 & 63 \\
    \hhline{|- ||*{8}{-}}
    \rowcolor[gray]{0.9}\multirow{2}{*}{\cellcolor{white}\large \textbf{3}}%
    & $ \beta_4 $ & $ \beta_3 $ & $ \beta_2 $ & $ \beta_1 $ & $ \gamma_1 $ & $ \gamma_2 $ & $ \gamma_3 $ & $ \gamma_4 $ \\
    \cline{2-9}
    & 1 & 2 & 3 & 6 & 7 & 14 & 21 & 42 \\
    \hhline{|-||*{8}{-}}
    \rowcolor[gray]{0.9} \multirow{2}{*}{\cellcolor{white}\large \textbf{6}}%
    & $ \beta_2 $ & $ \beta_1 $ & $ \gamma_1 $ & $ \gamma_2 $ \\
    \cline{2-5}
    & 1 & 3 & 7 & 21 \\
    \hhline{|-||*{6}{-}}
    \rowcolor[gray]{0.9} \multirow{2}{*}{\cellcolor{white}\large \textbf{7}}% 
    & $ \beta_3 $ & $ \beta_2 $ & $ \beta_1 $ & $ \gamma_1 $ & $ \gamma_2 $ & $ \gamma_3 $ \\
    \cline{2-7}
    & 1 & 2 & 3 & 6 & 9 & 18 \\
    \hhline{|-||*{6}{-}}
    \rowcolor[gray]{0.9} \multirow{2}{*}{\cellcolor{white}\large {\textbf{14}}}% 
    & $ \beta_1 $ & $ \boxdot^2 $ & $ \gamma_1 $ \\
    \cline{2-4}
    & 1 & 3 & 9 \\
    \hhline{|-||*{4}{-}}
    \rowcolor[gray]{0.9}\multirow{2}{*}{\cellcolor{white}\large {\textbf{21}}}% 
    & $ \beta_2 $ & $ \beta_1 $ & $ \gamma_1 $ & $ \gamma_2 $ \\
    \hhline{|~ ||*{4}{-}}
    & 1 & 2 & 3 & 6 \\
    \hhline{-||*{4}{-}}
    \rowcolor[gray]{0.9}\multirow{2}{*}{\cellcolor{white}\large {\textbf{42}}}%
    & $ \beta_1 $ & $ \gamma_1 $ \\
    \cline{2-3}
    & 1 & 3\\
    \hhline{|-||--}
\end{tabular}
\end{center}

\end{document} 

enter image description here

2
  • Great, Bernard! I had tried many workarounds, but none worked. It seemed strange to me that a system like Latex, the standard in the edition of scientific texts, presented this gross bug. Well, I had already decided to do without the gray shading, but now I will keep it, not only because it is what I wanted to do, but also because it represents a significant advance in my learning of this interesting discipline that is Latex. Thank you very much for the time you have dedicated to me and congratulations on your fantastic solution, which, without a doubt, will be useful to many more. Mar 28 at 10:58
  • Thank you for your kind appreciation. I don't think it's really a LaTeX bug, but rather some incompatibility between packages. This one has been known for quite some time. B.t. w., there was a possible simplification of the code that I didn't have time to test (it was late here when I answered); replacing all these row colors with a single \rowcolors{colour for odd rows}{colour for even rows} just before the tabular envt (details in the xcolor documentation). Also, using the array envt in the place of tabular, to remove all these pairs $$in cells.
    – Bernard
    Mar 28 at 11:13

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.