2

MWE:

I have tried several times to add \cline but without success...!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow, makecell, booktabs, tabularx, longtable}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}

\title{}
\author{}

\begin{document}
\maketitle


\rowcolors{1}{light-gray}{light-blue}
\begin{longtable}
{m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}}

\hline
\rowcolor{white}
& $Day$
& $Month$
& $Hours$
& $Feature 1$ 
& $Feature 2$
& $Feature 3$\\
\hline
%-------------------------------------------------
Friday
& $5$
& June
& 
& $A_1$
& $A_2$
& $A_3$
\\
\hline
%-------------------------------------------------
\global\rownum=2\relax
& 
& 
& $14 - 21$
& $B_1$
&
& $B_3$
\\
\multirow{-2}{*}[0em]{Saturday} 
& \multirow{-2}{*}[0em]{$6$} 
& \multirow{-2}{*}[0em]{June}
&
& $C_1$
& $C_2$
& $C_3$
\\
\hline
% -------------------------------------------------
\global\rownum=1\relax
& 
& 
& $08 - 10$
& $D_1$
& $D_2$
& $D_3$
\\
\global\rownum=1\relax
& 
&
& $10 - 17$
& $E_1$
&
& $E_3$
\\
\multirow{-3}{*}[0em]{Sunday}
& \multirow{-3}{*}[0em]{$7$}
& \multirow{-3}{*}[0em]{June}
& 
& $F_1$
& $F_2$
& $F_3$
\\
\hline
% -------------------------------------------------
\hiderowcolors
\\
\caption{This is a caption.}
\end{longtable}

\end{document}

What this code produces:

enter image description here

My desired output:

enter image description here

8
  • 1
    Unrelated to your question, but math mode isn't suitable to set text pieces like "Feature 1". Not only will the kerning be messed up, but you are also missing the spaces. Commented Feb 17, 2023 at 11:46
  • Ah ok, thanks a lot for your comment @samcarter_is_at_topanswers.xyz ! ....What would you suggest to repair this thing?
    – Ommo
    Commented Feb 17, 2023 at 11:48
  • 1
    Remove the math mode ($...$) around the words in your first row. If you want to emphasis them you could use \emph{...} instead Commented Feb 17, 2023 at 11:49
  • 1
    Is there some reason for using \multirow from the bottom up instead of the top down? Not that it matters since all it does is overlay the other rows. You could achieve the same effect with \raisebox. Commented Feb 17, 2023 at 14:45
  • 1
    Multirow does most of the calculations for you, so it is usually easier to use. Commented Feb 17, 2023 at 14:49

1 Answer 1

2

I suggest to use tabularray:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\title{}
\author{}

\begin{document}
    \maketitle
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}},
            row{1}={font=\itshape},
            cell{2-Z}{5-Z}={mode=math},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A_1
        & A_2
        & A_3
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B_1
        &
        & B_3
        \\
        &  
        & 
        &
        & C_1
        & C_2
        & C_3
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D_1
        & D_2
        & D_3
        \\
        & 
        &
        & 10 -- 17
        & E_1
        &
        & E_3
        \\
        & 
        & 
        & 
        & F_1
        & F_2
        & F_3
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

enter image description here

In case you used math mode only to have the subscripts, but your cells are actually only text:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\title{}
\author{}

\begin{document}
    \maketitle
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}},
            row{1}={font=\itshape},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & A\textsubscript{2}
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

enter image description here

16
  • Coooooolll @CarLaTex !!!! Many many thanks!!!! :-) So, basically, for this case, it's better to use (longtblr+SetCell) instead of (longtable + multirow + rownum).. Thanks!
    – Ommo
    Commented Feb 23, 2023 at 12:35
  • 1
    @limone You're welcome! Yes, tabularray is a new package and it is very convenient.
    – CarLaTeX
    Commented Feb 23, 2023 at 14:23
  • 1
    @limone Please ask a new question with a minimal example that reproduces your problem.
    – CarLaTeX
    Commented Mar 1, 2023 at 15:08
  • 1
    @limone It's difficult to reply without an example
    – CarLaTeX
    Commented Mar 1, 2023 at 16:18
  • 1
    @limone Is Zarko's answer OK for you?
    – CarLaTeX
    Commented Mar 1, 2023 at 18:09

You must log in to answer this question.

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