TransWikia.com

Color cell incomplete in coloured columns LaTeX and hhline details trouble

TeX - LaTeX Asked on December 31, 2021

I have a problem with my table in LaTeX. A few of cells doesn’t fill well.
I used the package "makecell" to do multirow and define new types of columns instead colortbl package (because I read that those packages can have a conflict), but I don’t know why is this happening. Also, I used hhline to do lines suitable to my table and I used a macro to change the color of line in each column(Btw, I have to deny the shorthands in the Spanish babel package to the macro works), but I still get the intersections in white.
Finally I modified the thick of the edges lines but it doesn´t work in all. Anyone could give me a suggestion, please? Thanks. Below is my code.

PD. I tried with "tabularx" and "tabulary" but it doesn’t work for me.

documentclass[10pt,a4paper]{report}
usepackage[utf8]{inputenc}
usepackage[spanish,es-noshorthands]{babel} %es-noshorthands sirve para que el cambio de color en hhline sea efectivo
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

usepackage[table,svgnames,x11names]{xcolor}
usepackage{hhline}
usepackage{multirow,makecell,array}
usepackage{diagbox}

usepackage{tabulary}
usepackage{adjustbox} 
usepackage{anyfontsize}

begin{document}
newcolumntype{g}{>{columncolor{LightSteelBlue}}c}
newcolumntype{h}{>{columncolor{Gainsboro}}c}
newcolumntype{k}{>{columncolor{Azure3}}c}

begin{table}
scriptsize
centering
begin{adjustbox}{max width=textwidth}
%!{vrule width1.2pt} modifica el ancho de linea vertical divisoria en la tabla, usar en vez de hline
% Xhline{1.2pt} modifica el ancho de linea horizontal divisoria en la tabla, usar en vez de solo |

begin{tabular}{!{vrule width1.2pt}g!{vrule width1.2pt}h!{vrule width1.2pt}k!{vrule width1.2pt}k!{vrule width1.2pt}}

%hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %hace una linea del color de la columna 1 y luego la cambia a color negro. Aplicar solo cuando tienes columnas de colores y hay problemas
%con el multirenglón. Si tu color de tabla es blanco con cline{-} (linea parcial) basta.

Xhline{1.2pt} %hline 
multicolumn{4}{|c|}{{textsc{Características y parámetros...}}} \ 

Xhline{1.2pt} %hline 
multicolumn{2}{|g|}{diagbox[innerwidth=7.5cm]{textbf{Ítem}}{textbf{Modelo}}} & textbf{Modelo1} & textbf{Modelo2} \ 

Xhline{1.2pt} %hline 
 & textbf{Material de máquina} & multicolumn{2}{|h|}{Estructuras de aluminio} \ 
hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-|}  %cline{2-4}               

 & textbf{Láser} & multicolumn{2}{|h|}{Generador de láser: Fibra óptica} \ %cline{2-4}

hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-}  %cline{2-4}
 & textbf{Potencia de salida} & $geq 20W$ & $geq 30W$ \ 

hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-}  %cline{2-4}
 & textbf{Longitud de onda} & multicolumn{2}{|h|}{$1064nm$} \ 

hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-}  %cline{2-4}
 & textbf{Lentes} & multicolumn{2}{|h|}{cellcolor{Gainsboro}makecell{Sistema de escaneo de alta precisión\2 dimensiones}} \ 

hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-}  %cline{2-4}
 & textbf{Velocidad de marcado} & multicolumn{2}{|h|}{$<8000mm/s$} \ 

hhline{|>{arrayrulecolor{LightSteelBlue}}-|>{arrayrulecolor{black}}-|-|-}  %cline{2-4} 
 &  & multicolumn{2}{|h|}{Pantalla* integrada} \ 
 
% 
 & multirowcell{-2}{textbf{Sistema de control principal}} & multicolumn{2}{|h|}{Controlador táctil externo 10.4''} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
multirowcell{-8}{Características\máquina\láser} & textbf{Sistema de enfriamiento} & multicolumn{2}{|h|}{cellcolor{Gainsboro} makecell{Sistema de enfriamiento\mediante agua o aire}} \ 
%------------------------------------------------------------------------
Xhline{1.2pt} %hline
 & cellcolor{Gainsboro} makecell{textbf{Aumento de enfoque}\ textbf{lentes (zoom)}} & multicolumn{2}{|h|}{190mm en doble enfoque con luz roja} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Tipo de fuente de marcado} & multicolumn{2}{|h|}{cellcolor{Gainsboro} makecell{Marcado elegible entre gráficos vectoriales\o mapas de bits}} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Ancho de línea mínimo} & multicolumn{2}{|h|}{$0.012mm$} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Precisión de repetibilidad} & multicolumn{2}{|h|}{0.003mm} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Área de trabajo} & multicolumn{2}{|h|}{$110mm x 110mm$} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Posicionamiento} & multicolumn{2}{|h|}{Luz roja posiciona, doble luz roja enfoca} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4}
 & textbf{Línea de marcado} & multicolumn{2}{|h|}{Sin límite el área de trabajo} \ 

hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---} %cline{2-4} 
multirowcell{-8}{Parámetros\de marcado\láser} & textbf{Velocidad} & multicolumn{2}{|h|}{$0-200m/min$} \ 
%-----------------------------------------------------------------
Xhline{1.2pt} %hline
 & textbf{Suministro de energía} & multicolumn{2}{|h|}{$220V$} \ 
%cline{2-4}
hhline{>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}---}
multirowcell{-2}{Otros} & textbf{Consumo de potencia} & multicolumn{2}{|h|}{$600W$} \ 
Xhline{1.2pt} %hline
end{tabular} 
end{adjustbox}
end{table}


end{document}

enter image description here

3 Answers

It is known that makecell has problems with table colouring, because there are nested tabulars with their own tabcolseps behind the scene. So I used Centerstack from stackengine. Further, to ensure the last two columns have equal width, I defined them as X columns and used a tabularx environment. Also used boldline for thick vertical lines for its simpler syntax, and simplified the use of hhline:

    documentclass[10pt, a4paper]{report}
    usepackage[utf8]{inputenc}
    usepackage[spanish,es-noshorthands]{babel} %es-noshorthands sirve para que el cambio de color en hhline sea efectivo
    usepackage{amsmath,amssymb}
    usepackage[margin=2cm]{geometry}
    usepackage[table,svgnames,x11names]{xcolor}
    usepackage{hhline}
    usepackage{boldline}
    usepackage{multirow,makecell,array}
    usepackage{diagbox}
    usepackage{tabularx}
    usepackage{tabulary}
    usepackage{adjustbox}
    usepackage[column= O]{cellspace}
    setlength{cellspacetoplimit}{3pt}
    setlength{cellspacebottomlimit}{3pt}
    addparagraphcolumntypes{X}
    usepackage{anyfontsize}
    usepackage[usestackEOL]{stackengine}
    usepackage{siunitx}

    begin{document}
    newcolumntype{g}{>{columncolor{LightSteelBlue}}c}
    newcolumntype{h}{>{columncolor{Gainsboro}}Oc}
    newcolumntype{k}{>{columncolor{Azure3}centeringarraybackslash}X}

    begin{table}
    scriptsize
    centering
    setlength{extrarowheight}{2pt}
    sisetup{range-phrase=--, range-units=single}
    begin{tabularx}{linewidth}{V{3}g V{3}h V{3}kV{3}k V{3}}%
    Xhline{1.2pt}
    multicolumn{4}{V{3}OcV{3}}{{textsc{Características y parámetros...}}} \
    Xhline{1.2pt}
    multicolumn{2}{V{3}gV{3}}{diagbox[innerwidth=6cm, linewidth=1.2pt]{textbf{Ítem}}{textbf{Modelo}}} & textbf{Modelo1} & textbf{Modelo2} \
    Xhline{1.2pt} %
     & textbf{Material de máquina} & multicolumn{2}{hV{3}}{Estructuras de aluminio} \[-0.5pt]
    hhline{~---}
     & textbf{Láser} & multicolumn{2}{hV{3}}{Generador de láser: Fibra óptica} \[-0.45pt]
    hhline{~---}
     & textbf{Potencia de salida} & $geq SI{20}{W}$ & $geq SI{30}{W}$ \[-0.5pt]
    hhline{~---}
     & textbf{Longitud de onda} & multicolumn{2}{hV{3}}{SI{1064}{nm}} \[-0.5pt]
    hhline{~---}
     & textbf{Lentes} & multicolumn{2}{hV{3}}{Centerstack{Sistema de escaneo de alta precisión\2 dimensiones}} \[-0.5pt]
    hhline{~---}
     & textbf{Velocidad de marcado} & multicolumn{2}{hV{3}}{$<SI{8000}{mmper s}$} \[-0.5pt]
    hhline{~---}
     & textbf{Sistema de control principal} & multicolumn{2}{hV{3}}{Centerstack{Pantalla* integrada \ Controlador táctil externo 10.4''}} \[-0.5pt]
    hhline{~---}
    multirowcell{-11}{Características\máquina láser} & textbf{Sistema de enfriamiento} & multicolumn{2}{hV{3}}{%
    Centerstack{Sistema de enfriamiento\mediante agua o aire}} \
    %------------------------------------------------------------------------
    Xhline{1.2pt}
     & Centerstack{textbf{Aumento de enfoque}\ textbf{lentes (zoom)}} & multicolumn{2}{hV{3}}{190,mm en doble enfoque con luz roja} \[-0.5pt]
    hhline{~---}
     & textbf{Tipo de fuente de marcado} & multicolumn{2}{hV{3}}{Centerstack{Marcado elegible entre gráficos vectoriales\o mapas de bits}} \[-0.5pt]
    hhline{~---}
     & textbf{Ancho de línea mínimo} & multicolumn{2}{hV{3}}{0.012,mm} \[-0.5pt]
    hhline{~---}
     & textbf{Precisión de repetibilidad} & multicolumn{2}{hV{3}}{0.003,mm} \[-0.45pt]
    hhline{~---}
     & textbf{Área de trabajo} & multicolumn{2}{hV{3}}{$SI{110}{mm} × SI{110}{mm}$} \[-0.5pt]
    hhline{~---}
     & textbf{Posicionamiento} & multicolumn{2}{hV{3}}{Luz roja posiciona, doble luz roja enfoca} \[-0.5pt]
    hhline{~---}
     & textbf{Línea de marcado} & multicolumn{2}{hV{3}}{Sin límite el área de trabajo} \[-0.5pt]
    hhline{~---}
    multirow{-10}{*}[2ex]{Centerstack{Parámetros\de marcado\láser}} & textbf{Velocidad} & multicolumn{2}{hV{3}}{SIrange{0}{200}{m/min}} \
    %-----------------------------------------------------------------
    Xhline{1.2pt}
     & textbf{Suministro de energía} & multicolumn{2}{hV{3}}{220,V} \[-0.45pt]
    hhline{~---}
    multirow{-2}{*}{Otros} & textbf{Consumo de potencia} & multicolumn{2}{hV{3}}{ 600,W } \
    Xhline{1.2pt}
    end{tabularx}
    end{table}

    end{document} 

enter image description here

Answered by Bernard on December 31, 2021

With use of the tabularx package and accordingly defined multicolumn cells:

documentclass[10pt,a4paper]{report}
usepackage[margin=2cm]{geometry}

usepackage[table,svgnames,x11names]{xcolor}
usepackage{hhline}
usepackage{makecell, multirow, tabularx}
newcolumntype{C}{>{centeringarraybackslash}X}
newcolumntype{L}{>{raggedrightarraybackslash}X}

usepackage{siunitx} % new

begin{document}
    begin{table}[ht]
    newcommandhlx {hhline{|>{arrayrulecolor{LightSteelBlue}}->{arrayrulecolor{black}}|-|-|-|}}
    newcommandhlxx{hhline{|>{arrayrulecolor{LightSteelBlue}}-->{arrayrulecolor{black}}|-|-|}}
    newcommandmcxx[1]{multicolumn{2}
                    {>{hsize=dimexpr 1.6hsize+2tabcolsep+1.2pt}C!{vrule width1.2pt}} % hsize=textwidth/4
                    {cellcolor{Gainsboro}{#1}}}
    renewcommandarraystretch{1.1}
    renewcommandtabularxcolumn[1]{m{#1}}
    small
    centering
begin{tabularx}{linewidth}
               {!{vrule width1.2pt}>{columncolor{LightSteelBlue}hsize=0.8hsize}X
                !{vrule width1.2pt}>{columncolor{Gainsboro}bfserieshsize=1.6hsize}L
                !{vrule width1.2pt}>{columncolor{Gainsboro}hsize=0.8hsize}C
                !{vrule width1.2pt}>{columncolor{Gainsboro}hsize=0.8hsize}C!{vrule width1.2pt}
               }
    Xhline{1.2pt}
multicolumn{4}{c}{textsc{Características y parámetros dots}}    \
    Xhline{1pt} 
    rowcolor{LightSteelBlue}
multicolumn{2}{!{vrule width1.2pt} c !{vrule width1.2pt}}{}                              
    & multicolumn{2}{c!{vrule width1.2pt}}{textbf{Modelo}}       \
    hlxx
    rowcolor{LightSteelBlue}
multicolumn{2}{!{vrule width1.2pt}
                >{hsize=dimexpr 2.4hsize+2tabcolsep+1.2pt}X
                !{vrule width1.2pt}
                }
               {multirow{-2}{=}{centeringtextbf{item}}}
            &   textbf{1}  &   textbf{1}                              \
    Xhline{1pt}
    &   Material de máquina
        &   mcxx{Estructuras de aluminio}                              \
    hlx
    & Láser 
        &   mcxx{Generador de láser: Fibra óptica}                     \
    hlx
    &   Potencia de salida
        &   cellcolor{Azure3}{$geq 20W$}
            &   cellcolor{Azure3}{$geq 30W$}                          \
    hlx
    & Longitud de onda          & mcxx{SI{1064}{nm}}                  \
    hlx
    & Lentes                    & mcxx{Sistema de escaneo de 
                                        alta precisión 2 dimensiones}   \
    hlx
    & Lentes                    & mcxx{Sistema de escaneo de
                                        alta precisión 2 dimensiones}   \
    hlx
    & Velocidad de marcado      & mcxx{SI{<8000}{mm/s}}               \
    hlx
    & Sistema de control principal
                                & mcxx{Controlador táctil externo SI{10.4}{''} 
                                        Pantalla* integrada}            \
    hlx
multirow{-12}{=}{Características máquina láser}
    & Sistema de enfriamiento   & mcxx{Sistema de enfriamiento
                                        mediante agua o aire}           \
%------------------------------------------------------------------------
    Xhline{1pt} 
    & Aumento de enfoque lentes (zoom)        
                                & mcxx{SI{190}{mm} en doble
                                        enfoque con luz roja}           \
    hlx
    & Tipo de fuente de marcado & mcxx{Marcado elegible entre gráficos
                                        vectoriales o mapas de bits}    \
    hlx
    & Ancho de línea mínimo     & mcxx{SI{0.012}{mm}}                 \
    hlx
    & Precisión de repetibilidad& mcxx{SI{0.003}{mm}}                 \
    hlx
    & Área de trabajo           & mcxx{SI{110x110}{mm}}               \
    hlx
    & Posicionamiento           & mcxx{Luz roja posiciona,
                                        doble luz roja enfoca}          \
    hlx
    & Línea de marcado          & mcxx{Sin límite el área de trabajo}  \
    hlx
multirow{-9}{=}{Parámetros de marcado láser}
    & Velocidad                 & mcxx{SIrange{0}{200}{m/min}}        \
%-----------------------------------------------------------------
    Xhline{1pt}
    & Suministro de energía     & mcxx{SI{220}{V}}                    \
    hlx
multirow{-2}{=}{Otros} 
    &   Consumo de potencia     & mcxx{SI{600}{W}}                    \
    Xhline{1.2pt}
end{tabularx}
    end{table}
end{document}

enter image description here

Answered by Zarko on December 31, 2021

Here is what you can do with the environment {NiceTabular} of nicematrix.

  • You can merge cells both horizontally and vertically with the command Block.

  • The key hvlines draws all the rules except in the blocks. Of course, these rules have all a width (thickness) equal to arrayrulewidth. That's why I have drawn the heavy rules after.

  • nicematrix creates PGF/Tikz nodes under the array. It's possible to use these nodes with Tikz. That's what I have done to draw the heavy rules.

  • nicematrix provides a built-in command diagbox

The code:

documentclass[10pt,a4paper]{report}
usepackage[spanish]{babel}
usepackage[T1]{fontenc}
usepackage{lmodern}

usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
usepackage[svgnames,x11names]{xcolor}
usepackage{nicematrix}
usepackage{tikz}

begin{document}

begin{table}
centering


begin{NiceTabular}{wc{2cm}>{bfseries}ccc}[hvlines,cell-space-limits = 4pt]
CodeBefore
  columncolor{LightSteelBlue}{1}
  rectanglecolor{Gainsboro}{3-2}{-}
  rowcolor{white}{1}
  rectanglecolor{LightSteelBlue}{2-1}{2-2}
  rectanglecolor{Azure3}{2-3}{2-4}
  rectanglecolor{Azure3}{5-3}{5-4}
Body
  Block{1-4}{textsc{Características y parámetros...}} & & & \ 
  Block{1-2}{diagbox{strut Ítem}{strut Modelo}} & & makebox[3.5cm][c]{textbf{Modelo1}} &
  makebox[3.5cm][c]{textbf{Modelo2}} \ 
  Block{9-1}{Características\máquina\láser}
   & Material de máquina & Block{1-2}{Estructuras de aluminio} \ 
   & Láser & Block{1-2}{Generador de láser: Fibra óptica} \
   & Potencia de salida & $geq 20$ W & $geq 30$ W \ 
   & Longitud de onda & Block{1-2}{$1064$ nm} \ 
   & Lentes & Block{1-2}{Sistema de escaneo de alta precisión\2 dimensiones} \ 
   & Velocidad de marcado & Block{1-2}{$<8000$ mm/s} \ 
   & Block{2-1}{textbf{Sistema de control principal}} & Block{1-2}{Pantalla* integrada} \ 
   &  & Block{1-2}{Controlador táctil externo $10.4''$} \ 
   & Sistema de enfriamiento & Block{1-2}{Sistema de enfriamiento\mediante agua o aire} \ 
  %------------------------------------------------------------------------
  Block{8-1}{Parámetros\de marcado\láser} 
   & Block{1-1}{Aumento de enfoque\ lentes (zoom)} & Block{1-2}{$190$ mm en doble enfoque con luz roja} \ 
   & Tipo de fuente de marcado &  Block{1-2}{Marcado elegible entre gráficos vectoriales\o mapas de bits} \ 
   & Ancho de línea mínimo & Block{1-2}{$0.012$ mm} \ 
   & Precisión de repetibilidad & Block{1-2}{$0.003$ mm} \ 
   & Área de trabajo & Block{1-2}{$110$ mm $times$ $110$ mm} \ 
   & Posicionamiento & Block{1-2}{Luz roja posiciona, doble luz roja enfoca} \ 
   & Línea de marcado & Block{1-2}{Sin límite el área de trabajo} \ 
   & Velocidad & Block{1-2}{$0$-$200$ m/min} \ 
  %-----------------------------------------------------------------
  Block{2-1}{Otros} & Suministro de energía & Block{1-2}{$220$ V} \ 
   & Consumo de potencia & Block{1-2}{$600$ W} 
CodeAfter
  tikz
  draw [line width = 1.2pt]
    (1-|1) rectangle (22-|5) 
    (2-|1)  -- (2-|5) 
    (3-|1)  -- (3-|5) 
    (12-|1) -- (12-|5) 
    (20-|1) -- (20-|5) 
    (3-|2)  -- (22-|2) 
    (2-|3)  -- (22-|3) ;
end{NiceTabular} 

end{table}

end{document}

You need two compilations (because informations, in particular for PGF/Tikz nodes, will be written on the aux file after the first compilation).

Output of the above code

Answered by F. Pantigny on December 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP