2

When trying to create a table with color-filled cells, it appears that the last cell of each segment has an extra width than the others.

I created the table using this website, the code generated is:

\begin{table}[]
\begin{tabular}{|c|l|l|llll|llll|llll|llll|}
\hline
\textbf{Fase}       & \multicolumn{1}{c|}{\textbf{Etapa}}                                                    & \multicolumn{1}{c|}{\textbf{Actividades}} & \multicolumn{4}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}Semestre\\ 2025-1\end{tabular}}}                   & \multicolumn{4}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}Semestre \\ 2025-2\end{tabular}}}                  & \multicolumn{4}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}Semestre\\ 2026-1\end{tabular}}}                   & \multicolumn{4}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}Semestre\\ 2026-2\end{tabular}}}                   \\ \hline
                    &                                                                                        & Actividad 1                               & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          \\
                    &                                                                                        & Actividad 2                               &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          \\
\multirow{-3}{*}{1} & \multirow{-3}{*}{\begin{tabular}[c]{@{}l@{}}Primera etapa del\\ proyecto\end{tabular}} & Actividad 3                               &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          \\ \hline
                    &                                                                                        & Actividad 1                               &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          \\
                    &                                                                                        & Actividad 2                               &                          &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          &                          \\
\multirow{-3}{*}{2} & \multirow{-3}{*}{\begin{tabular}[c]{@{}l@{}}Segunda etapa del\\ proyecto\end{tabular}} & Actividad 3                               &                          &                          &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          &                          &                          &                          \\ \hline
                    &                                                                                        & Actividad 1                               &                          &                          &                          &                          &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          &                          \\
                    &                                                                                        & Actividad 2                               &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} &                          &                          &                          &                          \\
\multirow{-3}{*}{3} & \multirow{-3}{*}{\begin{tabular}[c]{@{}l@{}}Tercera etapa del\\ proyecto\end{tabular}} & Actividad 3                               &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          &                          & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} & \cellcolor[HTML]{000000} \\ \hline
\end{tabular}
\end{table}

and the result is

table

As you can see, the cells on the right (for each term) are much wider than the previous three cells.

1
  • 1
    Off-topic: \begin{table}[] is a bad idea; replace with either \begin{table} or \begin{table}[htbp].
    – Mico
    Commented Jul 23 at 23:42

2 Answers 2

3

That is because the cellin the first row (e.g. Semestre\\ 2025-1) is wider than 4 of the black cells. So the last one of the four swallows up the extra space. You can make them a bit wider for example with

\newcommand\black{\cellcolor[HTML]{000000}\hspace*{1mm}}

and then replace all the \cellcolor[HTML]{000000} in the table by \black. By the way, instead of \cellcolor[HTML]{000000} you can use \cellcolor{black}, which looks a bit nicer.

enter image description here

3

An alternative way for codding your table:

  • without use of tabular generator (which usually produce a lot of clutter code)
  • since you not provide an MWE (Minimal Working Example), a complete small document, by which we will see your document pages layout (your table is quite wide ...)
  • for table use tabularray package
  • for last 16 columns use equal width of columns, defined by X columns
  • for cells coloring define new command which enable to write shorter code
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\NewTableCommand\scb{\SetCell{bg=black}}

\begin{document}
    \begin{table}
\begin{tblr}{colspec = {|c|l|l|*{4}{*{4}{X[c]}|}},
             cell{1}{4,8,12,16} = {c=4}{},
             cell{2,5,8}{1,2} = {r=3}{},
             row{1}  = {m, font=\small\bfseries}
             }
\hline
Fase    &   Etapa 
            &   Actividades
                &   {Semestre\\ 2025-1}                   
                    &   &   &   &   {Semestre \\ 2025-2}
                                    &   &   &   &   {Semestre\\ 2026-1}
                                                    &   &   &   &   {Semestre\\ 2026-2}   
                                                                    &   &   &   \\ 
\hline
1       &   {Primera etapa\\ del proyecto}        
            &   Actividad 1 
                &   \scb 
                    &   \scb 
                        &   &   &   &   &   &   &   &   &   &   &   &   &   &   \\           
        &   &   Actividad 2
                &   &   \scb 
                        &   \scb 
                            &   &   &   &   &   &   &   &   &   &   &   &   &   \\
        &   &   Actividad 3                               
                &   &   & \scb 
                            & \scb &    &   &   &   &   &   &   &   &   &   &   \\ 
\hline
2       &   {Segunda etapa\\ del proyecto}        
            &   Actividad 1 
                &   &   &   &   &   \scb 
                                        &   \scb 
                                            &   &   &   &   &   &   &   &   &   \\     
        &   &   Actividad 2
                &   &   &   &   &   &   \scb 
                                        &   \scb 
                                            &   &   &   &   &   &   &   &   &   \\     
        &   &   Actividad 3                               
                &   &   &   &   &   &   &   \scb 
                                                &   \scb 
                                                    &   &   &   &   &   &   &   \\     
\hline
3       &   {Tercera etapa\\ del proyecto}        
            &   Actividad 1 
                &   &   &   &   &   &   &   &   &   \scb 
                                                    &   \scb 
                                                        &   \scb   
                                                            &   &   &   &   &   \\     
        &   &   Actividad 2                                                         
                &   &   &   &   &   &   &   &   &   &   &   \scb 
                                                            &   \scb 
                                                                &   &   &   &   \\
        &   &   Actividad 3                               
                &   &   &   &   &   &   &   &   &   &   &   &   \scb    
                                                                &   \scb 
                                                                    &   \scb 
                                                                        &   \scb 
                                                                            &   \scb \\ 
\hline
\end{tblr}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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