지정된 표 행의 글꼴 색상을 변경하려고 할 때 컴파일 할 수 없음

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에서만 사용할 수 있음을 언급하는 것이 중요합니다. 또한 몇 가지 다른 제한 사항이 있지만 대부분의 경우 접근 방식이 잘 작동합니다.

Usign 접근 방식

를 사용하여 좋아하는 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