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.

azzamsa
  • 201

1 Answers1

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

CarLaTeX
  • 62,716
  • 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 03 '19 at 16:51
  • Which multicolumn package? – Bernard May 03 '19 at 16:58
  • @azzamsa See my edit. – CarLaTeX May 03 '19 at 17:12
  • @Bernard I think azzamsa intended multirow. – CarLaTeX May 03 '19 at 17:13
  • @CarLaTeX this also didn't work for me (hope there will be a fix for longtable). For now I will you your updated solution (to use header every new page) or to adjust any break with \hline usage instead of cline manually. You saved my day, thank you so much, hope you have great days there. – azzamsa May 03 '19 at 17:22
  • @azzamsa You can also avoid having header on every page, if you like, just remove the code between \endfirsthead (excluded) and \endhead (included). – CarLaTeX May 03 '19 at 17:24
  • @CarLaTeX tried it, but didn't work, maybe cline override those values. I will stick with manual adjustment for now. – azzamsa May 03 '19 at 17:39
  • 1
    @azzamsa Try with \hline\endhead after \endfirsthead. – CarLaTeX May 03 '19 at 17:54
  • @CarLaTeX oh no!. Your idea work. Instead of using two complex solution above I presented (which didn't work for me, and I am afraid also it affect other part of my document) adding \hline\endhead\hline\endfoot after \endfirsthead work great for me. Billion thanks for you CarLatex :). I don't know why I never think of this tricky approach. – azzamsa May 03 '19 at 18:10