指定された表形式の行のフォントの色を変更しようとするとコンパイルできません
Nov 22 2020
パッケージtabular
を使用せずに、の行全体のテキストの色を変更しようとしていtabu
ます。この答えを採用したい。
次のMWEがコンパイルされないように、私は何を間違っていますか?「LaTeXエラー:コマンド@はすでに定義されています」というエラーメッセージが表示されます。
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage{booktabs}
\usepackage{acro}
\usepackage{siunitx}
\sisetup{%
detect-family, detect-shape,
product-units = power,
list-final-separator = {, and },
retain-explicit-plus,
input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim}
}
\DeclareSIUnit[number-unit-product = ]\percent{\char`\%}
% Code from https://tex.stackexchange.com/a/26364/15622
\newcommand*{\@rowstyle}{}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
\gdef\@rowstyle{#1}%
\@rowstyle\ignorespaces%
}
\newcolumntype{=}{% resets the row style
>{\gdef\@rowstyle{}}%
}
\newcolumntype{+}{% adds the current row style to the next column
>{\@rowstyle}%
}
\makeatother
\begin{document}
\begin{table}
\centering
\begin{tabular}{=l +l +l}
\toprule
A & {B} & {C}\\
\midrule
\rowstyle{\color{red}}
Bob & \SI{75}{\percent} & -1.11\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
\end{document}
回答
2 MarianG. Nov 22 2020 at 15:33
コメントするには長すぎます。次のアプローチが、テーブルの選択した行、残りの行、または色の指定を繰り返さずにさらに多くの行に色を付ける必要がある場合の代替手段になることを願っています。
出力

このソリューションはpdfTeXでのみ使用できることに注意してください。また、他にもいくつかの制限がありますが、多くの場合、このアプローチは問題なく機能します。
アプローチに署名する
たとえば、を使用して、お気に入りのRGBカラー仕様を定義するだけ\def\mycolor{.6 0 .8}
です。さらに、\rowclr
行の先頭(または通常は行のどこか)でコマンドを使用して、行の残りの部分に色を付けます。定義された色を適用するには、を記述し\rowclr\mycolor
ます。一度に複数の行を着色する必要がある場合は、コマンドを使用することをお勧めします\startclr\mycolor
と\stopclr
ターンオフする着色。
コード
\documentclass[oneside,11pt]{book}
\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage{booktabs}
\usepackage{acro}
\usepackage{siunitx}
\sisetup{%
detect-family, detect-shape,
product-units = power,
list-final-separator = {, and },
retain-explicit-plus,
input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim}
}
\DeclareSIUnit[number-unit-product = ]\percent{\char`\%}
% declare your favorite rgb color specifications here
\def\mycolor{.6 0 .8}
\def\othercolor{1 .2 .5}
\def\somecolor{.5 .8 .3}
\def\stopclr{\pdfliteral{0 g}}
\def\startclr#1{\pdfliteral{#1 rg}}
% color the 'rest' of the row
\def\rowclr#1#2\\{\startclr#1#2\stopclr\\}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ccc}
%------------------------------------
\toprule
A & B & C\\
\midrule
%------------------------------------
\rowclr\mycolor
Bob & \SI{75}{\percent} & -1.11\\
%------------------------------------
Carla & \startclr\othercolor \SI{75}{\percent}& 2.22\\
%------------------------------------
Dale\stopclr & \SI{75}{\percent} & -3.33\\
%------------------------------------
Ena & \rowclr\somecolor\SI{75}{\percent} & 4.44\\
%------------------------------------
\bottomrule
\end{tabular}
\caption{A}
\end{table}
\end{document}
jsbibra Nov 22 2020 at 10:10

\documentclass[oneside,11pt]{book}
\usepackage{xcolor}
%\usepackage[semibold,tt=false]{libertine}
%\usepackage{libertinust1math}
%\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
%\usepackage[subrefformat=parens]{subcaption}
%\usepackage[
% expansion = false ,
% tracking = smallcaps ,
% letterspace = 40 ,
%]{microtype}
\usepackage{booktabs}
%\usepackage{acro}
\usepackage{siunitx}
\sisetup{%
detect-family, detect-shape,
product-units = power,
list-final-separator = {, and },
retain-explicit-plus,
input-comparators = {<=>\approx\ge\geq\gg\le\leq\ll\sim\lesssim\gtrsim}
}
\DeclareSIUnit[number-unit-product = ]\percent{\char`\%}
% Code from https://tex.stackexchange.com/a/26364/15622
\makeatletter
\newcommand*{\@rowstyle}{}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
\gdef\@rowstyle{#1}%
\@rowstyle\ignorespaces%
}
\newcolumntype{=}{% resets the row style
>{\gdef\@rowstyle{}}%
}
\newcolumntype{+}{% adds the current row style to the next column
>{\@rowstyle}%
}
\makeatother
\begin{document}
\begin{table}
\centering
\begin{tabular}{=l +l +l}
\toprule
A & {B} & {C}\\
\midrule
\rowstyle{\color{red}}
Bob & \SI{75}{\percent} & -1.11\\
Carla & \SI{75}{\percent} & 2.22\\
Dale & \SI{75}{\percent} & -3.33\\
Ena & \SI{75}{\percent} & 4.44\\
\bottomrule
\end{tabular}
\caption{A}
\end{table}
\end{document}
t