5

I have this code:

\documentclass{article}
\usepackage{array,multirow,xcolor,colortbl}
\definecolor{tableheadercolor}{HTML}{FFCE63}  % Orange from the Keams template
\colorlet{tablerowcolor}{tableheadercolor!20} % 20% header color + 80% white

\begin{document}

\begin{table}[ht]
    \centering
    \caption{Opened and Closed JIRA Tickets for ED by Month}
    \begin{tabular}{|
    >{\centering\arraybackslash}m{0.1\textwidth}|
    >{\centering\arraybackslash}m{0.15\textwidth}|
    >{\centering\arraybackslash}m{0.15\textwidth}|
    >{\centering\arraybackslash}m{0.15\textwidth}|}
        \hline
        \rowcolor{tableheadercolor}
        \textbf{Year} & \textbf{Month} & \textbf{Opened JIRAs} & \textbf{Closed JIRAs} \\
        \hline
        \multirow{1}{*}{\centering 2023} & December & 2 & 1 \\
        \hline
        \multirow{12}{*}{\cellcolor{tablerowcolor}\centering 2024} & \cellcolor{tablerowcolor} January & \cellcolor{tablerowcolor} 1 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & February & 0 & 1 \\
        \cline{2-4} & \cellcolor{tablerowcolor} March & \cellcolor{tablerowcolor} 0 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & April & 0 & 0 \\
        \cline{2-4} & \cellcolor{tablerowcolor} May & \cellcolor{tablerowcolor} 3 & \cellcolor{tablerowcolor} 1 \\
        \cline{2-4} & June & 0 & 0 \\
        \cline{2-4} & \cellcolor{tablerowcolor} July & \cellcolor{tablerowcolor} 0 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & August & 2 & 2 \\
        \cline{2-4} & \cellcolor{tablerowcolor} September & \cellcolor{tablerowcolor} 0 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & October & 1 & 0 \\
        \cline{2-4} & \cellcolor{tablerowcolor} November & \cellcolor{tablerowcolor} 1 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & December & 2 & 1 \\
        \hline
        \multirow{11}{*}{\centering 2025} & \cellcolor{tablerowcolor} January & \cellcolor{tablerowcolor} 2 & \cellcolor{tablerowcolor} 8 \\
        \cline{2-4} & February & 4 & 2 \\
        \cline{2-4} & \cellcolor{tablerowcolor} March & \cellcolor{tablerowcolor} 0 & \cellcolor{tablerowcolor} 3 \\
        \cline{2-4} & April & 8 & 4 \\
        \cline{2-4} & \cellcolor{tablerowcolor} May & \cellcolor{tablerowcolor} 2 & \cellcolor{tablerowcolor} 0 \\
        \cline{2-4} & June & 2 & 4 \\
        \cline{2-4} & \cellcolor{tablerowcolor} July & \cellcolor{tablerowcolor} 1 & \cellcolor{tablerowcolor} 4 \\
        \cline{2-4} & August & 2 & 1 \\
        \cline{2-4} & \cellcolor{tablerowcolor} September & \cellcolor{tablerowcolor} 1 & \cellcolor{tablerowcolor} 3 \\
        \cline{2-4} & October & 2 & 0 \\
        \cline{2-4} & \cellcolor{tablerowcolor} November & \cellcolor{tablerowcolor} 0 & \cellcolor{tablerowcolor} 1 \\
        \hline
    \end{tabular}
\end{table}

\end{document}

However, the row for year 2024 is not correctly shaded: Table with incorrect shading

What I want to achieve is rows with alternate shading.

1
  • I've taken the liberty of augmenting your code snippet to make it minimally compilable. Commented yesterday

2 Answers 2

5

(I updated and simplified my answer after I spotted a coding error in the OP's code.)

My maintain suggestion is to change

\multirow{12}{*}{\cellcolor{tablerowcolor}\centering 2024}

to

\multirow{12}{*}{\centering 2024}

Can you spot the difference?

While you're at it, you may also want to (a) change the four column types to clcc, (b) get rid of all vertical rules, and (c) get rid of all \hline and \cline{2-4} directives. Trust me, neither the vertical nor the horizontal rules are needed.

enter image description here

\documentclass{article}
\usepackage{array,multirow,xcolor,colortbl}
\definecolor{tableheadercolor}{HTML}{FFCE63}  % Orange from the Keams template
\colorlet{tablerowcolor}{tableheadercolor!20} % 20% header color + 80% white
\newcommand\zzz{\cellcolor{tablerowcolor}}

\begin{document}
\renewcommand\familydefault\sfdefault % optional -- switch to sans serif 

\begin{table}[ht]
    \centering
    \caption{Opened and Closed JIRA Tickets for ED by Month}
    \begin{tabular}{clcc}
        
        \rowcolor{tableheadercolor}
        \textbf{Year} & \textbf{Month} & \textbf{Opened JIRAs} & \textbf{Closed JIRAs} \\
        
        2023 & December & 2 & 1 \\[2ex]
        
        \multirow{12}{*}{2024} & \zzz January & \zzz 1 & \zzz 0 \\
        & February & 0 & 1 \\
        & \zzz March & \zzz 0 & \zzz 0 \\
        & April & 0 & 0 \\
        & \zzz May & \zzz 3 & \zzz 1 \\
        & June & 0 & 0 \\
        & \zzz July & \zzz 0 & \zzz 0 \\
        & August & 2 & 2 \\
        & \zzz September & \zzz 0 & \zzz 0 \\
        & October & 1 & 0 \\
        & \zzz November & \zzz 1 & \zzz 0 \\
        & December & 2 & 1 \\[2ex]
        
        \multirow{12}{*}{2025} & \zzz January & \zzz 2 & \zzz 8 \\
        & February & 4 & 2 \\
        & \zzz March & \zzz 0 & \zzz 3 \\
        & April & 8 & 4 \\
        & \zzz May & \zzz 2 & \zzz 0 \\
        & June & 2 & 4 \\
        & \zzz July & \zzz 1 & \zzz 4 \\
        & August & 2 & 1 \\
        & \zzz September & \zzz 1 & \zzz 3 \\
        & October & 2 & 0 \\
        & \zzz November & \zzz 0 & \zzz 1 \\      
    \end{tabular}
\end{table}

\end{document}

Addendum to address the OP's follow-up question: To give the first column a color shading --, say, tableheadercolor -- just use the \columncolor macro (provided by the colortbl package) in the first column's specification. Note that once \columncolor is used, it's necessary to place the \multirow directives in the final rather rather than in the first row of their scope.

Aside: I can't see a (compelling) reason for bold-facing the material in the header row, especially as you're already giving it lots of visual prominence by shading the entire header row.

enter image description here

%% code for 2nd screenshot (add color shading for first column)
\documentclass{article}
\usepackage{array,multirow,xcolor,colortbl}
\definecolor{tableheadercolor}{HTML}{FFCE63}  % Orange from the Keams template
\colorlet{tablerowcolor}{tableheadercolor!20} % 20% header color + 80% white
\newcommand\zzz{\cellcolor{tablerowcolor}} % handy shortcut macro

\begin{document}

\renewcommand\familydefault\sfdefault % optional: switch to sans serif 
\begin{table}[ht]
    \centering
    \setlength\extrarowheight{2pt} % for a less-cramped "look"
    \caption{Opened and Closed JIRA Tickets for ED by Month}
    
    \smallskip
    \begin{tabular}{>{\columncolor{tableheadercolor}}clcc}
        
        \rowcolor{tableheadercolor}
        Year & Month & Opened JIRAs & Closed JIRAs \\[0.5ex] %<-- increase the visual prominence
        
        2023 & December & 2 & 1 \\[2ex]
        
        & \zzz January & \zzz 1 & \zzz 0 \\
        & February & 0 & 1 \\
        & \zzz March & \zzz 0 & \zzz 0 \\
        & April & 0 & 0 \\
        & \zzz May & \zzz 3 & \zzz 1 \\
        & June & 0 & 0 \\
        & \zzz July & \zzz 0 & \zzz 0 \\
        & August & 2 & 2 \\
        & \zzz September & \zzz 0 & \zzz 0 \\
        & October & 1 & 0 \\
        & \zzz November & \zzz 1 & \zzz 0 \\
        \multirow{-12}{*}{2024} 
        & December & 2 & 1 \\[2ex]
        
        & \zzz January & \zzz 2 & \zzz 8 \\
        & February & 4 & 2 \\
        & \zzz March & \zzz 0 & \zzz 3 \\
        & April & 8 & 4 \\
        & \zzz May & \zzz 2 & \zzz 0 \\
        & June & 2 & 4 \\
        & \zzz July & \zzz 1 & \zzz 4 \\
        & August & 2 & 1 \\
        & \zzz September & \zzz 1 & \zzz 3 \\
        & October & 2 & 0 \\
        \multirow{-10}{*}{2025} 
        & \zzz November & \zzz 0 & \zzz 1 \\      
    \end{tabular}
\end{table}

\end{document}
5
  • Thanks for the suggestion. However, if you do that the first column (year) has no alternate shading. Also, although I agree I can go without the vertical and horizontal rules, as this is an adaptation of a Word company template, I have to stick as close as possible to the Word format... so that they don't realise I didn't use Word to create the report. Commented yesterday
  • @Álvaro - IMNSHO, there should be no alternating row shading at all in the first column. I trust it’ll be easy for you to put the vertical and horizontal rules back in. Aside: It’s deeply depressing to learn just how strongly many people — you’re not included in this set, obviously — appear to believe that only tables created by MS Word are trustworthy tables… Commented yesterday
  • Maybe as an alternative, could it possible to shade the whole first column? So no alternative shading, just shade the whole column. And yes, it's true that most companies are saddled with a Microsoft dependency. But that could lead to a whole conversation. Commented 22 hours ago
  • @Álvaro - I've posted an addendum to address your follow-up question on how to go about shading the whole first column. Commented 13 hours ago
  • 1
    Hello Mico, I liked your last table. Shading the whole column will make the trick and make it look "Word style" lol. However, as I generate this table automatically with Python, it took me a bit of work to change the logic from doing the multirow at the beginning, to do it at the end. But problem solved! Thanks a lot :) Commented 4 hours ago
3

Here is an easy way to create that table with {NiceTabular} of nicematrix.

For the alternating row shading, you only have to put the instruction \rowcolors{tableheadercolor!20}{} in the cell where it begins, that is to say, in the third row and the second column (the shading will apply to the columns on the right of the second column because the command is used in the second column).

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}

\definecolor{tableheadercolor}{HTML}{FFCE63} 

\begin{document}

\begin{table}[ht]
\centering
\small \sffamily
\caption{Opened and Closed JIRA Tickets for ED by Month}
\begin{NiceTabular} [hvlines]
  {w{c}{0.1\textwidth}*{3}{w{c}{0.15\textwidth}}}
\RowStyle[fill=tableheadercolor]{\bfseries}    
Year & Month & Opened JIRAs & Closed JIRAs \\
2023 & December & 2 & 1 \\
\Block{12-1}{2024}
     & \rowcolors{tableheadercolor!20}{}
       January   & 1 & 0 \\
     & February  & 0 & 1 \\
     & March     & 0 & 0 \\
     & April     & 0 & 0 \\
     & May       & 3 & 1 \\
     & June      & 0 & 0 \\
     & July      & 0 & 0 \\
     & August    & 2 & 2 \\
     & September & 0 & 0 \\
     & October   & 1 & 0 \\
     & November  & 1 & 0 \\
     & December  & 2 & 1 \\
\Block{11-1}{2025}
     & January   & 2 & 8 \\
     & February  & 4 & 2 \\
     & March     & 0 & 3 \\
     & April     & 8 & 4 \\
     & May       & 2 & 0 \\
     & June      & 2 & 4 \\
     & July      & 1 & 4 \\
     & August    & 2 & 1 \\
     & September & 1 & 3 \\
     & October   & 2 & 0 \\
     & November  & 0 & 1 \\ 
\end{NiceTabular}
\end{table}

\end{document}

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

Output of the above code

1
  • However, I would recommend a design with booktabs in the spirit of booktabs. Commented 21 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.