0

I'm currently trying to use \cline to help me replicate this mockup: Draft of what I wish to accomplish

I've been stumped for a while and the closest I've come to replicate it is the following:

\documentclass{article}
\usepackage[left=0.75in,top=0.6in,right=0.75in,bottom=1.2in]{geometry}
\usepackage[utf8]{}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{tcolorbox}
\usepackage{enumitem}
\usepackage{makecell}
\usepackage{hyperref}
\usepackage{longtable,array}
\usepackage{booktabs,ragged2e}
\usepackage[default,oldstyle,scale=0.95]{opensans}
\urlstyle{sf}
\title{t}


\begin{document}
\begin{longtable}{>{\raggedright\arraybackslash}m{5.5cm}|>{\raggedright\arraybackslash}m{2.0cm} |>{\raggedright\arraybackslash}m{2.0cm}|>{\raggedright\arraybackslash}m{6.5cm}}
    \bfseries \cellcolor[gray]{.8}Column1 & 
    \bfseries \cellcolor[gray]{.8}Column2 &
    \bfseries \cellcolor[gray]{.8}Column3 & 
    \bfseries \cellcolor[gray]{.8}Notes\\ 
    \hline
    
    General Chemistry& %row 1
    -- \newline-- \newline --&\\\cline{2-2}& %row 2
    &ch121\newline ch122\newline ch123&\\\cline{3-3}&&ch231/261\newline ch232/262\newline ch233/262&
    ch121-123 available online at OSU\\\hline
    

\end{longtable}

\end{document}

which produces this table: enter image description here

As you can see, I wish to have every column's text start at the top but it seems that using cline creates a weird vertical indentation. For example, I would like it so that the horizontal line between column 2 and column 3 were at the same level:

enter image description here

Is there a way to "flush" my input after every usage of cline? I've tried looking through cline man pages such as: https://latexref.xyz/_005ccline.html, https://www.giss.nasa.gov/tools/latex/ltx-214.html and other stack questions to no avail.

Thanks in advance.

2 Answers 2

1

Your fundamental misunderstanding is that you need to give every data entry for a row, then the \\ to end the row, and then any \cline or \hline commands.

Your second problem is that you're loading booktabs. I really like booktabs, but its documentation is clear that you should not use vertical lines under any circumstances, and that tables with booktabs may not work right with vertical lines.

I'm not familiar enough with long table, but I wasn't seeing any affect of >{\raggedright\arraybackslash}, so I took it out.

I put "General Chemistry" in row 3. If you really want it between rows 3 and 4, you can use a \multirow as in the other answer.

It's not needed for this example, so I took it out, but with few exceptions, hyperref should be the last package loaded.

Without booktabs, you end up with this:

\documentclass{article}
\usepackage[left=0.75in,top=0.6in,right=0.75in,bottom=1.2in]{geometry}
\usepackage[table]{xcolor}
\usepackage{longtable}
%\usepackage{booktabs}
\usepackage[default,oldstyle,scale=0.95]{opensans}

\begin{document}
\begin{longtable}{m{5.5cm}|m{2.0cm}|m{2.0cm}|m{6.5cm}}
    \bfseries \cellcolor[gray]{.8}Column1 & 
    \bfseries \cellcolor[gray]{.8}Column2 &
    \bfseries \cellcolor[gray]{.8}Column3 & 
    \bfseries \cellcolor[gray]{.8}Notes\\ 
    \hline
    
    & -- & ch121 & \\%row 1
    & -- & ch122 & ch121-123 available online at OSU \\%row 2
    General Chemistry & -- & ch123 \\ % row 3
    \cline{2-3}
    && ch231/261 & \\ % row 4
    && ch232/262 & \\ % row 5
    && ch233/262 & \\ % row 6
    \hline
\end{longtable}

\end{document}

which looks like: non-booktabs output

A basic idea of booktabs is that taking out extra lines leaves few distractions and makes a table easier to understand. The package would approach the table something like the following:

\documentclass{article}
\usepackage[left=0.75in,top=0.6in,right=0.75in,bottom=1.2in]{geometry}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[default,oldstyle,scale=0.95]{opensans}

\begin{document}
\begin{longtable}{m{5.5cm} m{2.0cm} m{2.0cm} m{6.5cm}}
    \toprule
    Column1 & Column2 & Column3 & Notes\\ 
    \midrule
    
    General Chemistry & -- & ch121 & ch121-123 available online at OSU \\%row 1
    & -- & ch122 & \\%row 2
    & -- & ch123 \\ % row 3
    \cmidrule{2-3}
    && ch231/261 & \\ % row 4
    && ch232/262 & \\ % row 5
    && ch233/262 & \\ % row 6
    \bottomrule
\end{longtable}

\end{document}

which looks like: booktabs output

It's hard to tell whether the \cmidrule should still be there without seeing more of the table.

1
  • Great explanation. Please also add an image to your version without booktabs to visually illustrate the difference between the two versions.
    – Unknown
    Commented May 27, 2022 at 21:02
2

Here is a solution to your problem:

\documentclass{article}
\usepackage[left=0.75in,top=0.6in,right=0.75in,bottom=1.2in]{geometry}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{xcolor,colortbl}% \rowcolor

\begin{document}
\begin{longtable}{p{5.5cm}|p{2.0cm}|p{2.0cm}|p{6.5cm}}
    \rowcolor{gray!40}
    \textbf{Column1} & \textbf{Column2} & \textbf{Column3} & \textbf{Notes}\\
    \hline

    \multirow{6}*{General Chemistry} & -- & ch121 & \multirow{3}*{ch121-123 available online at OSU}\\
    & -- & ch122 & \\
    & -- & ch123 & \\
    \cline{2-3}
    & & ch231/261 & A\\
    & & ch232/262 & B\\
    & & ch233/263 & C\\
    \hline
\end{longtable}

% Use this if your table is not longer than one page.
\begin{table}
    \begin{tabular}{p{5.5cm}|p{2.0cm}|p{2.0cm}|p{6.5cm}}
        \rowcolor{gray!40}
        \textbf{Column1} & \textbf{Column2} & \textbf{Column3} & \textbf{Notes}\\
        \hline

        \multirow{6}*{General Chemistry} & -- & ch121 & \multirow{3}*{ch121-123 available online at OSU}\\
        & -- & ch122 & \\
        & -- & ch123 & \\
        \cline{2-3}
        & & ch231/261 & A\\
        & & ch232/262 & B\\
        & & ch233/263 & C\\
        \hline
    \end{tabular}
\end{table}
\end{document}

Table with \multirow and \cline.

You must log in to answer this question.

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