LaTeX 中多行表格上的行颜色

发布于 2024-08-28 07:07:22 字数 1126 浏览 8 评论 0 原文

所以我昨晚尝试学习 LaTeX,我试图尽快完成学校作业的这个模板。其中一部分需要构建一个表。我想使用多行,但需要将充当标题的多行设置为灰色。这就是我迄今为止从万能的谷歌创建的。

\documentclass{article}
\usepackage{xcolor,colortbl}
\begin{document}

\begin{tabular}{|l|l|p{5cm}|p{2.5cm}|l|l|}
\hline
\rowcolor{lightgray} 
Stage & Aim & Procedure & Materials & Focus & Time \\ 
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Engage} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
%\hline
\rowcolor{lightgray} \multicolumn{6}{|l|}{Study} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Activate} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Conclusion} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\end{tabular}

\end{document}

不幸的是,这不适用于我在虚拟机中的 Debian GNU/Linux 5.0.4 (lenny) 上的 pdflatex 版本 1.4.0。它没有正确执行,最终看起来像这个,其中第一个单元格多行之后的行是黑色垃圾。

So I tried learning LaTeX last night, and I trying to get this template for school assignments done ASAP. Part of that requires building a table. I want to use multirow, but need the multirows, that are acting like headings, to be colored gray. This is what I created so far from the almighty Google.

\documentclass{article}
\usepackage{xcolor,colortbl}
\begin{document}

\begin{tabular}{|l|l|p{5cm}|p{2.5cm}|l|l|}
\hline
\rowcolor{lightgray} 
Stage & Aim & Procedure & Materials & Focus & Time \\ 
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Engage} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
%\hline
\rowcolor{lightgray} \multicolumn{6}{|l|}{Study} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Activate} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\rowcolor{lightgray} 
\multicolumn{6}{|l|}{Conclusion} \\
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\end{tabular}

\end{document}

Unfortunately, this does not work with pdflatex version 1.4.0 on Debian GNU/Linux 5.0.4 (lenny) I have in a VM. Instead of doing it correctly, it ends up looking like this, where the first cell of the row after the multirow is blacked-out garbage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故笙诉离歌 2024-09-04 07:07:22

试试这个:

\documentclass{article}

\usepackage{xcolor,colortbl}

\begin{document}

\begin{tabular}{|l|l|p{5cm}|p{2.5cm}|l|l|}

\hline
Stage & Aim & Procedure & Materials & Focus & Time \\ 
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Engage} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Study} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Activate} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Conclusion} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline

\end{tabular}

\end{document}

它会产生:

编辑:

是的,>{...} 是放置 \columncolor 的命令(必须位于其中!)。另请参阅 此 PDF

Try this:

\documentclass{article}

\usepackage{xcolor,colortbl}

\begin{document}

\begin{tabular}{|l|l|p{5cm}|p{2.5cm}|l|l|}

\hline
Stage & Aim & Procedure & Materials & Focus & Time \\ 
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Engage} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Study} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Activate} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline
\multicolumn{6}{|>{\columncolor[gray]{.8}}l|}{Conclusion} \\ 
\hline
Row 0 & Row 1 & Row 2 & Row 3 & Row 4 & Row 5 \\
\hline

\end{tabular}

\end{document}

Which produces:

alt text

EDIT:

Yes, >{...} is the command to place your \columncolor in (must be in it!). Also see 4.1 from this PDF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文