
演習の解答を書くために、表に答えを赤で記入したいと思います。表の見出しは演習と同じスタイルのままにし、表の一部のみを色付けする必要があります。表の\textcolor{red}{...}
各セルで を使用することでこれを実現できますが、かなり面倒です。環境表の最後まで、後続のすべての単語が赤でなければならないことを宣言するソリューションを探しています。
いくつか試してみましたが\color{red}
、うまくいきませんでした。
ここに小さな例があります。
\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}
望ましい出力:
PS: Fe2O3 が間違った場所にあることは承知しています。これは 2 番目の要素のためだけのものでした :) !
答え1
テーブル内のすべてのエントリも を使用していると仮定すると\ch
、次のように独自のコマンドを定義できます。
\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}
\newcommand{\redch}[1]{\textcolor{red}{\ch{#1}}}
\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
&& & & & & & & & &\redch{C6H12O6}\\
\hline
&& \redch{Fe2O3} & & & & & & & &\\
\hline
&& & & & & & & & &\\
\hline
&& & & & & & & & &\\
\hline
&& & & & & & & & &\\
\hline
&& & & & & & & & &\\
\hline
\end{tabular}
\end{center}
\end{document}
\setchemformula{format=\color{red}}
環境の内部を使用して、その環境の内部center
の色を変更すること もできます。\ch
\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}
\setchemformula{format=\color{red}}
\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}
答え2
考えられる解決策は(質問を正しく理解していれば)、\color{red}
すべての列にコマンドを送信することです。この目的のために、新しい列タイプを定義しましたR
。その後、見出しテキストを で囲んで、\multicolumn{1}{c|}{<text>}
色付けを防ぎます。
適応できるかもしれないデビッド・カーライルのこの質問への回答コードに追加し、 -command \rowfont
(これもコード内で定義) を受け入れる新しい列を定義します。
例1 –\rowfont
コマンドの定義
\documentclass[11pt,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}
例 2 – >{color{red} and
\multicolon}}
\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}