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

Ommo
  • 835
  • 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. – samcarter_is_at_topanswers.xyz Feb 17 '23 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 Feb 17 '23 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 – samcarter_is_at_topanswers.xyz Feb 17 '23 at 11:49
  • Thanks a lot, I will do it ! :-) – Ommo Feb 17 '23 at 11:53
  • 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. – John Kormylo Feb 17 '23 at 14:45
  • Hello @JohnKormylo, thanks for the comment... :-) Well, there is not any particular reason, I just found quite easy and straightforward to split the rows by using \multirows, and I did not deepen much more this aspect... never used \raisebox so far.. :-). In general, what I would like to achieve is exactly what I have showed at the end of my question, that I called "My desired output".. that would be my final goal.. and I am open to new solutions :-) – Ommo Feb 17 '23 at 14:48
  • 1
    Multirow does most of the calculations for you, so it is usually easier to use. – John Kormylo Feb 17 '23 at 14:49
  • Hi, Anyone here who can help in this regard? ......I am getting quite crazy (and frustrated) about finding a solution :-) – Ommo Feb 21 '23 at 11:03

1 Answers1

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

CarLaTeX
  • 62,716
  • Coooooolll @CarLaTex !!!! Many many thanks!!!! :-) So, basically, for this case, it's better to use (longtblr+SetCell) instead of (longtable + multirow + rownum).. Thanks! – Ommo Feb 23 '23 at 12:35
  • 1
    @limone You're welcome! Yes, tabularray is a new package and it is very convenient. – CarLaTeX Feb 23 '23 at 14:23
  • Great! Before to start using longtable I was indeed thinking if tabularray with longtblr could be more convenient..... Indeed, According to "Make a table span multiple pages"(https://tex.stackexchange.com/questions/26462/make-a-table-span-multiple-pages) there are two main options: (1) longtable (239 votes from August 2011 to February 2023) and (2) longtblr environment from tabularray (8 votes from August 2021 to February 2023) ...but then, since longtable was out for a longer time, I thought to use it (just one criterion since I have not experience) – Ommo Feb 23 '23 at 15:29
  • @limone If you have an up-to-date TeX distribution, there are no problems using tabularray. – CarLaTeX Feb 23 '23 at 16:32
  • Yes, I currently have Tex Live Version: 2020 (Legacy), but I can also set the 2021 version and the 2022 version... Many thanks :-) – Ommo Feb 24 '23 at 09:28
  • I have a small question about your table... To set the horizontal spaces of each column you used this command colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{1.5cm} m{1.5cm}}.....but what is the maximum amount of space I can use (for each column) not to go beyond the maximum page width allowed? (and possibly keeping the table still centered?) – Ommo Feb 28 '23 at 18:29
  • thanks, @CarLaTeX :-) ....actually, by using colspec={*{7}{l}},, the entire table "stretches" towards the right margin of the page and it "goes out" the page... :-) – Ommo Mar 01 '23 at 09:48
  • Thanks, by using colspec={*{7}{X[l]}},, the table structure/layout is well-centered and looks fine. However, the text goes out of the table structure/layout, and out of the page..... :-) – Ommo Mar 01 '23 at 13:01
  • 1
    @limone Please ask a new question with a minimal example that reproduces your problem. – CarLaTeX Mar 01 '23 at 15:08
  • Yes, you are perfectly right! (Sorry for asking here, I thought it could be a small thing) :-) – Ommo Mar 01 '23 at 15:32
  • 1
    @limone It's difficult to reply without an example – CarLaTeX Mar 01 '23 at 16:18
  • Please see the. new question: https://tex.stackexchange.com/questions/676953/increase-the-width-of-a-longtblr-table – Ommo Mar 01 '23 at 17:18
  • 1
    @limone Is Zarko's answer OK for you? – CarLaTeX Mar 01 '23 at 18:09
  • Thanks for asking :-) Well, I think it is a great reply, and I am thankful to Zarko... However, if I understood correctly, he/she decreased the width of the 5th column (and maybe of the 7th one as well?), in order to make the overall table width as wide as the manuscript text (please see the figure I posted in that question to visualize it better). Nevertheless, as I wrote him/her in a comment, my desire was to just work (i.e. to increase) on the 6th column, and keep all the other columns still, i.e. with the same width that I initially set... – Ommo Mar 02 '23 at 09:03
  • @limone I had no time today, but you accepted Zarko's answer, so I think it is OK now – CarLaTeX Mar 02 '23 at 22:21
  • Yes yes, it is fine, very kind! Thanks :-) – Ommo Mar 03 '23 at 09:28