1

I have working code which produce the image below:

\documentclass[12pt,a4paper,oneside]{report}

\usepackage{ragged2e}
\usepackage{longtable, makecell}
\newcolumntype{L}[1]{>{\RaggedRight}p{#1}}
\renewcommand\theadfont{\small\bfseries}
\setcellgapes{3pt}

\begin{document}

{\makegapedcells
  \begin{longtable}{|c|L{2.5cm}|L{5cm}|L{1.8cm}|L{2.1cm}|}
    \caption{My Table}\\
    \hline
    \thead{No} & \thead{A} & \thead{B} & \thead{C} &  \thead{D} \\\hline
    %
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\hline
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\hline
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\hline
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\hline
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
  \end{longtable}
}

\end{document}

However I want to remove some line in the certain cell to become like this:

Thank you in advance.

1 Answer 1

3

Simply use \cline{fromcolumn-tocolumn}.

\documentclass[12pt,a4paper,oneside]{report}

\usepackage{ragged2e}
\usepackage{longtable, makecell}
\newcolumntype{L}[1]{>{\RaggedRight}p{#1}}
\renewcommand\theadfont{\small\bfseries}
\setcellgapes{3pt}

\begin{document}

{\makegapedcells
  \begin{longtable}{|c|L{2.5cm}|L{5cm}|L{1.8cm}|L{2.1cm}|}
    \caption{My Table}\\
    \hline
    \thead{No} & \thead{A} & \thead{B} & \thead{C} &  \thead{D} \\\hline
    %
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
  \end{longtable}
}

\end{document}

enter image description here

Edit: in case of a table which goes on many pages, with \pagebreak you can force a page break to avoid the separation of a group of cells.

\documentclass[12pt,a4paper,oneside]{report}

\usepackage{ragged2e}
\usepackage{longtable, makecell}
\newcolumntype{L}[1]{>{\RaggedRight}p{#1}}
\renewcommand\theadfont{\small\bfseries}
\setcellgapes{3pt}

\begin{document}

{\makegapedcells
  \begin{longtable}{|c|L{2.5cm}|L{5cm}|L{1.8cm}|L{2.1cm}|}
    \caption{My Table}\\
    \hline
    \thead{No} & \thead{A} & \thead{B} & \thead{C} &  \thead{D} \\\hline
    \endfirsthead
    \hline
    \thead{No} & \thead{A} & \thead{B} & \thead{C} &  \thead{D} \\\hline
    \endhead
    %
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
        \pagebreak
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
    1 & FOO-01 & Lorem ipsum dolor sit amet & John & Lorem \\\cline{1-3}
    1.1 & FOO-01-01 & consectetur adipiscing elit. &  & \\\cline{1-3}
    1.2 & FOO-01-02 & curabitur ut quam eu. & & \\\hline
    2 & FOO-02 & Nam posuere turpis et & Doe & Ipsum\\\cline{1-3}
    2.1 & FOO-02-01 & consectetur adipiscing elit. & &\\\cline{1-3}
    2.2 & FOO-02-02 & curabitur ut quam eu. & &\\\hline
  \end{longtable}
}

\end{document}

enter image description here

enter image description here

10
  • Whoa, thank you. I am afraid of using multicolumn package. Turn out there is simpler solution. Never heard of cline thanks. However cline didn't work if the table spread out in more than one page. ltcilne didn't work with my code above. Need help.
    – azzamsa
    May 3, 2019 at 16:51
  • Which multicolumn package?
    – Bernard
    May 3, 2019 at 16:58
  • @azzamsa See my edit.
    – CarLaTeX
    May 3, 2019 at 17:12
  • @Bernard I think azzamsa intended multirow.
    – CarLaTeX
    May 3, 2019 at 17:13
  • 1
    @azzamsa Try with \hline\endhead after \endfirsthead.
    – CarLaTeX
    May 3, 2019 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.