質問: To write the solution of an exercise, i want to fill in the tabular with the answers in red. The headlines of the table should stay in the same style than the exercise and only a part of the table should be colorized. I can achieve that by using `\textcolor{red}{...}` in each cell of my table but it's pretty brutal. I'm looking for a solution to declare that all the following words must be in red untill the end of the environment tabular. I've tried some `\color{red}` but it doesn't work. Here is a small example. ``` \documentclass[11pt,a4paper]{report} \usepackage[utf8]{inputenc} \usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm]{geometry} \usepackage{colortbl} \usepackage{chemformula} \begin{document} \begin{center} \footnotesize \renewcommand{\arraystretch}{1.5} \hspace*{-1cm}\begin{tabular}{|c|c|c||c|c|c|c|c|c|c|c|} \hline \rowcolor{black} \multicolumn{11}{|c|}{\textcolor{white}{Corps purs}}\\\hline \rowcolor{gray!90} élémentaires& \multicolumn{2}{c||}{simples} & \multicolumn{8}{c|}{composés}\\ \hline \rowcolor{gray!70} &métal.& non-métal. & \multicolumn{2}{c|}{Oxydes} & Hydroxydes & \multicolumn{2}{c|}{Acides} & \multicolumn{2}{c|}{Sels} & Corps organiques\\ \hline \rowcolor{gray!50} && & métal. & non-métal. & & bin. & tern. & bin. & tern. &\\ \hline && & & & & & & & &\ch{C6H12O6}\\ \hline && \ch{Fe2O3} & & & & & & & &\\ \hline && & & & & & & & &\\ \hline && & & & & & & & &\\ \hline && & & & & & & & &\\ \hline && & & & & & & & &\\ \hline \end{tabular} \end{center} \end{document} ``` Desired output : ![enter image description here](https://i.stack.imgur.com/uaAJ1.png) PS : i'm aware that Fe2O3 is at the wrong place, it was only for a second element :) !
回答: A possible solution (if I understand your question correct) is to direct a `\color{red}` command into all columns. I have defined a new column type `R` for the purpose. Thereafter, you enclose the heading text in `\multicolumn{1}{c|}{}` to protect against colourisation. You may adapt David Carlisle answer to this question to your code, and define a new column that accepts a `\rowfont`-command (also defined in the code): **Example 1 – defining a `\rowfont`-command** !enter image description here ``` \documentclass11pt,a4paper]{report} \usepackage[utf8]{inputenc} \usepackage{array} \newcolumntype{C}{>{\rowfont}c} \newcommand\setrowfont[1]{\noalign{\gdef\rowfont{#1}}} \gdef\rowfont{} \usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm]{geometry} \usepackage{colortbl} \usepackage{chemformula} \begin{document} \begin{center} \footnotesize \renewcommand{\arraystretch}{1.5} \hspace*{-1cm}\begin{tabular}{|*{3}{C|}|*{8}{C|}} \hline \rowcolor{black} \multicolumn{11}{|c|}{\textcolor{white}{Corps purs}}\\\hline \rowcolor{gray!90} élémentaires & \multicolumn{2}{c||}{simples} & \multicolumn{8}{c|}{composés}\\ \hline \rowcolor{gray!70} & métal. & non-métal. & \multicolumn{2}{c|}{Oxydes} & Hydroxydes & \multicolumn{2}{c|}{Acides} & \multicolumn{2}{c|}{Sels} & Corps organiques\\ \hline \rowcolor{gray!50} && & métal. & non-métal. & & bin. & tern. & bin. & tern. &\\ \hline \setrowfont{\color{red}} && X& & & & & & & &\ch{C6H12O6}\\ \hline && \ch{Fe2O3} & & & & & & & &\\ \hline X&X& X & X & X & X & X & X & X & X &X\\ \hline && X& & & & & & & &\\ \hline && X& & & & & & & &\\ \hline && X& & & & & & & &\\ \hline \end{tabular} \end{center} \end{document} ``` **Example 2 – `>{color{red} and`\multicolomn}}** ![enter image description here ``` \documentclass[11pt,a4paper]{report} \usepackage[utf8]{inputenc} \usepackage{array} \usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm]{geometry} \newcolumntype{R}{>{\color{red}}c} \usepackage{colortbl} \usepackage{chemformula} \begin{document} \begin{center} \footnotesize \renewcommand{\arraystretch}{1.5} \hspace*{-1cm}\begin{tabular}{|*{3}{R|}|*{8}{R|}} \hline \rowcolor{black} \multicolumn{11}{|c|}{\textcolor{white}{Corps purs}}\\\hline \rowcolor{gray!90} \multicolumn{1}{c|}{élémentaires} & \multicolumn{2}{c||}{simples} & \multicolumn{8}{c|}{composés}\\ \hline \rowcolor{gray!70} & \multicolumn{1}{c|}{métal.} & \multicolumn{1}{c||}{non-métal.} & \multicolumn{2}{c|}{Oxydes} & \multicolumn{1}{c|}{Hydroxydes} & \multicolumn{2}{c|}{Acides} & \multicolumn{2}{c|}{Sels} & \multicolumn{1}{c|}{Corps organiques}\\ \hline \rowcolor{gray!50} && & \multicolumn{1}{c|}{métal.} & \multicolumn{1}{c|}{non-métal.} & & \multicolumn{1}{c|}{bin.} & \multicolumn{1}{c|}{tern.} & \multicolumn{1}{c|}{bin.} & \multicolumn{1}{c|}{tern.} &\\ \hline && X& & & & & & & &\ch{C6H12O6}\\ \hline && \ch{Fe2O3} & & & & & & & &\\ \hline X&X& X & X & X & X & X & X & X & X &X\\ \hline && X& & & & & & & &\\ \hline && X& & & & & & & &\\ \hline && X& & & & & & & &\\ \hline \end{tabular} \end{center} \end{document} ```