TransWikia.com

Table header color not working as i want

TeX - LaTeX Asked by L00n3y on April 13, 2021

I want the header of my table to be red but as you can see in the example it is red but also it seems there is a white extra column left to it. I can not seem to figure out why it is there. And how to remove it and get it fully red.

Below example table:
example table

Below the code:

documentclass[11pt, a4paper]{article}
usepackage[a4paper,top=2cm,hmargin=2cm,bottom=3cm,]{geometry}
usepackage{xcolor,colortbl}
usepackage[utf8]{inputenc}
usepackage{tikz}
usepackage{tikzpagenodes}
usepackage{fancyhdr}
usepackage{xcolor}
usepackage{colortbl}
usepackage[utf8]{inputenc}
usepackage{titletoc}
usepackage[T1]{fontenc}
usepackage{sectsty}
usepackage{float}
usepackage{atbegshi}
usepackage{fontspec}
usepackage{graphicx}
usepackage{tabu}
begin{document}
    noindentbegin{tabular*}{columnwidth}{@{extracolsep{fill}} |l|l|l|l|l|l|l|}
    hline
    rowcolor[RGB]{227,24,24}color{white}largebfseries Nr &color{white}largebfseries IP & color{white}largebfseries TL1 & color{white}largebfseries TL2 & color{white}largebfseries TL3 & color{white}largebfseries TL4 & color{white}largebfseries TL5 hline 
    1. & 1.1.1.1 & 5 & 0 & 1 & 0 & 0 hline
    2. & 1.2.3.4 & 5 & 0 & 0 & 0 & 0 hline
    3. & 5.5.5.5 & 2 & 1 & 1 & 1 & 1 hline
    4. & 95.231.766.33 & 1 & 0 & 0 & 0 & 0 hline
    5. & 115.231.796.313 & 1 & 0 & 0 & 0 & 0 hline
    6. & 115.231.776.313 & 1 & 0 & 0 & 0 & 0 hline
    7. & 715.231.76.313 & 1 & 0 & 0 & 0 & 0 hline
    8. & 415.231.76.313 & 1 & 0 & 0 & 0 & 0 hline
    9. & 315.231.76.313 & 1 & 0 & 0 & 0 & 0 hline
    10. & 215.231.76.313 & 1 & 0 & 0 & 0 & 0 hline
    11. & 115.231.76.33 & 0 & 0 & 3 & 0 & 0 hline
    12. & 95.271.76.33 & 0 & 0 & 2 & 0 & 0 hline
    13. & 95.231.786.33 & 0 & 0 & 1 & 0 & 0 hline
    14. & 95.231.756.33 & 0 & 0 & 1 & 0 & 0 hline
    15. & 95.231.746.33 & 0 & 0 & 1 & 0 & 0 hline
    16. & 95.231.736.33 & 0 & 0 & 1 & 0 & 0 hline
    17. & 95.231.726.33 & 0 & 0 & 1 & 0 & 0 hline
    18. & 95.231.716.33 & 0 & 0 & 1 & 0 & 0 hline
    end{tabular*}
end{document}

2 Answers

tabular* inserts space between the columns, and that is what you are seeing with the white gaps. Forcing the columns apart just make the table harder to read so simplest is to use a normal tabular

Correct answer by David Carlisle on April 13, 2021

If you actually want your tabular to have a width equal to the maximal width (which is probably not a good idea), you can use {NiceTabular*} of nicematrix. The built-in command rowcolor of that environment will color the whole row as expected.

documentclass[11pt, a4paper]{article}
usepackage[a4paper,top=2cm,hmargin=2cm,bottom=3cm,]{geometry}
usepackage{nicematrix}

begin{document}
    newcommand{thead}{color{white}largebfseriessffamily}
    arrayrulecolor[RGB]{227,24,24}
    noindentbegin{NiceTabular*}{columnwidth}{@{extracolsep{fill}}llccccc}[colortbl-like,hvlines]
    rowcolor[RGB]{227,24,24}thead Nr &thead IP & thead TL1 & thead TL2 & thead TL3 & thead TL4 & thead TL5  
    1. & 1.1.1.1 & 5 & 0 & 1 & 0 & 0 
    2. & 1.2.3.4 & 5 & 0 & 0 & 0 & 0 
    3. & 5.5.5.5 & 2 & 1 & 1 & 1 & 1 
    4. & 95.231.766.33 & 1 & 0 & 0 & 0 & 0 
    5. & 115.231.796.313 & 1 & 0 & 0 & 0 & 0 
    6. & 115.231.776.313 & 1 & 0 & 0 & 0 & 0 
    7. & 715.231.76.313 & 1 & 0 & 0 & 0 & 0 
    8. & 415.231.76.313 & 1 & 0 & 0 & 0 & 0 
    9. & 315.231.76.313 & 1 & 0 & 0 & 0 & 0 
    10. & 215.231.76.313 & 1 & 0 & 0 & 0 & 0 
    11. & 115.231.76.33 & 0 & 0 & 3 & 0 & 0 
    12. & 95.271.76.33 & 0 & 0 & 2 & 0 & 0 
    13. & 95.231.786.33 & 0 & 0 & 1 & 0 & 0 
    14. & 95.231.756.33 & 0 & 0 & 1 & 0 & 0 
    15. & 95.231.746.33 & 0 & 0 & 1 & 0 & 0 
    16. & 95.231.736.33 & 0 & 0 & 1 & 0 & 0 
    17. & 95.231.726.33 & 0 & 0 & 1 & 0 & 0 
    18. & 95.231.716.33 & 0 & 0 & 1 & 0 & 0 
    end{NiceTabular*}
end{document}

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

Output of the above code

Answered by F. Pantigny on April 13, 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