1

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}
    \noindent\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} |l|l|l|l|l|l|l|}
    \hline
    \rowcolor[RGB]{227,24,24}\color{white}\large\bfseries Nr &\color{white}\large\bfseries IP & \color{white}\large\bfseries TL1 & \color{white}\large\bfseries TL2 & \color{white}\large\bfseries TL3 & \color{white}\large\bfseries TL4 & \color{white}\large\bfseries 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}
leandriis
  • 62,593
L00n3y
  • 13

2 Answers2

2

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

David Carlisle
  • 757,742
0

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}\large\bfseries\sffamily} \arrayrulecolor[RGB]{227,24,24} \noindent\begin{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

F. Pantigny
  • 40,250