
연습문제의 답을 작성하기 위해 표에 빨간색으로 답을 채우고 싶습니다. 표의 헤드라인은 연습문제와 동일한 스타일을 유지해야 하며 표의 일부에만 색상을 지정해야 합니다. 내 테이블의 각 셀을 사용하여 이를 달성할 수 있지만 \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}
원하는 출력:
추신: Fe2O3가 잘못된 위치에 있다는 것을 알고 있습니다. 두 번째 요소에만 해당됩니다 :)!
답변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
-command 정의
\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
\다열}}
\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}