如何删除单元格表格中的线?

如何删除单元格表格中的线?

我有生成以下图像的工作代码:

\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}

但是我想删除特定单元格中的某些行,使其变成这样:

先感谢您。

答案1

只需使用\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}

在此处输入图片描述

编辑:如果表格跨越多页,\pagebreak您可以强制分页以避免分隔一组单元格。

\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}

在此处输入图片描述

在此处输入图片描述

相关内容