LaTeX:单元格边框

问题描述

我想在 LaTeX 表格中添加单元格的水平边框(或完全重新定义表格以获得相同的结果)。我目前的定义是:

\begin{table}[h!]
\resizeBox{\textwidth}{!}{%
    \begin{tabular}{
    >{\columncolor[HTML]{EFEFEF}}l l}
    \hline
        \multicolumn{2}{l}{\cellcolor[HTML]{EFEFEF}\textbf{1^{st}} \textbf{Category Title}}  \\ 
    \hline
        Description    & 
        \begin{tabular}{p{20cm}}
            Lorem ipsum dolor sit amet,consectetuer adipiscing elit.
        \end{tabular} \\
        Effect & 
        \begin{tabular}{p{20cm}}
            Proin in tellus sit amet nibh dignissim sagittis. Integer in sapien. Class aptent 
            taciti sociosqu ad litora torquent per conubia nostra,per inceptos hymenaeos.
        \end{tabular} \\ 
    \hline
    \end{tabular}%
}
\caption{Category table}
\label{tab:categ_list}
\end{table} 

看起来像这样:

enter image description here

并且我想添加水平线以使用文本分割单元格:

enter image description here

我找到了一个带有 \arrayrulecolor[HTML]{CFCFCF}\hline解决方案,它看起来不错,但 \hline 分隔整行,而不仅仅是单个单元格。我也试过 \cline 但这不起作用(没有出现单元格边框,而且整行都消失了)。

解决方法

您可以添加一个

\cline{2-2}

Effect 之前的代码行中。

出于两个原因,我简化了您的代码:

  • 标题最初丢失了,我不知道使用什么包来运行颜色语法(所以,抱歉,下面缺少颜色);
  • 我坚信没有必要嵌套多个 tabular 环境,您可以使用更简洁、更整洁的代码来实现。

我的草图:

\documentclass{article}
\usepackage{multicol}

\def\arraystretch{1.5}

\begin{document}
\begin{table}%[h!]
\begin{tabular}{lp{10cm}}
\hline
\multicolumn{2}{l}{$\mathbf{1^{st}}$\textbf{ Category Title}}\\ 
\hline
Description & Lorem ipsum dolor sit amet,consectetuer adipiscing elit\\
\cline{2-2}
Effect & Proin in tellus sit amet nibh dignissim sagittis. Integer in sapien. 
Class aptent taciti sociosqu ad litora torquent per conubia nostra,per inceptos hymenaeos.\\ 
\hline
\end{tabular}
\caption{Category table}
\label{tab:categ_list}
\end{table} 

\end{document}

输出:

screenshot of output

希望对你有帮助,否则请评论!

最后,如@samcarter 对您的问题的评论中所述,您可以检查此样式和未来表格的包 booktabs,没有垂直边框线。