newcommand에서 xcolor 색상 혼합을 작동시키는 방법

newcommand에서 xcolor 색상 혼합을 작동시키는 방법

명령에 전달된 인수를 사용하여 테이블 셀의 색상을 설정하고 싶지만 아무런 효과가 없는 것 같습니다. 내 코드는 다음과 같습니다.

\PassOptionsToPackage{table}{xcolor}
\documentclass{beamer}

\usepackage{xcolor}

\newcommand*{\heatmap}[1][]{\cellcolor{red!#1} {#1}}
\begin{document}

\section{Background}

\begin{frame}
    \frametitle{The size and type of repeats}
    \begin{tabular}{lcccc}
        Species & genomes & G/C & A/T & Di-\\
        Widget & 7 & \heatmap{97}\% & \heatmap{3}\% & 0\%\\
    \end{tabular}
\end{frame}

\end{document}

내 기대는 매크로가 사용된 두 개의 셀이 \heatmap그때 다른 색조의 빨간색으로 나올 것이라는 것입니다. 그러나 실제로는 둘 다 완전한 빨간색으로 나옵니다. 이러한 상황에서 명령이 작동하도록 하려면 어떻게 해야 합니까?

답변1

명령에 선택적 인수가 필요하도록 만드는 경우입니다(이 경우에는 적절하지 않은 것 같습니다). 차이점을 비교해보세요:

\PassOptionsToPackage{table}{xcolor}
\documentclass{beamer}

\usepackage{xcolor}

\newcommand*{\heatmap}[1][]{\cellcolor{red!#1} {#1}}
\newcommand*{\xheatmap}[1]{\cellcolor{red!#1} {#1}}
\begin{document}

\section{Background}

\begin{frame}
    \frametitle{The size and type of repeats}
    \begin{tabular}{lcccc}
        Species & genomes & G/C & A/T & Di-\\
        Widget & 7 & \heatmap[97]\% & \heatmap[30]\% & 0\%\\
        Widget & 7 & \heatmap[57]\% & \heatmap[30!blue!30]\% & 0\%\\
        Widget & 7 & \xheatmap{97}\% & \xheatmap{30}\% & 0\%\\
    \end{tabular}
\end{frame}

\end{document}

관련 정보