![使用投影機顏色](https://rvso.com/image/400344/%E4%BD%BF%E7%94%A8%E6%8A%95%E5%BD%B1%E6%A9%9F%E9%A1%8F%E8%89%B2.png)
為了避免顏色過多,我使用投影機的顏色來強調文字的項目。它看起來像這樣:
\documentclass[xcolor=dvipsnames]{beamer}
\usetheme{Madrid}
\newcommand{\gn}[1]{\textcolor{block title example.bg}{{}#1{}}}
\begin{document}
\begin{frame}{Green text}
\gn{This isn't working.}
\begin{example}[boring example]
nothing to see here.
\end{example}
\gn{This is green.}
This is black.
\end{frame}
\end{document}
現在,如果我嘗試在投影機第一次使用顏色之前使用它(如“這不起作用”),我會收到錯誤:
Package xcolor Error: Undefined color `block title example.bg'.
有辦法解決這個問題嗎?
答案1
\usebeamercolor[bg]{block title example}
會使用顏色
\documentclass[xcolor=dvipsnames]{beamer}
\usetheme{Madrid}
\newcommand{\gn}[1]{{\usebeamercolor[bg]{block title example}#1}}
\begin{document}
\begin{frame}{Green text}
\gn{This isn't working.}
\begin{example}[boring example]
nothing to see here.
\end{example}
\gn{This is green.}
This is black.
\end{frame}
\end{document}