
我想使用傳遞到命令中的參數來設定表格單元格的顏色,但它似乎沒有任何效果。這是我的程式碼:
\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}