Generalmy \newcommand not working :-(

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dmorgan
Posts: 5
Joined: Tue Nov 10, 2009 8:18 pm

my \newcommand not working :-(

Post by dmorgan »

Hi Everyone/Anyone

Using Beamer, I occasionally want to customize the colors for a block title background and body background to match one of the colors in an illustration on that slide.

It goes like this:

\begin{frame}
\setbeamercolor{block title}{bg=earthGreen}
\setbeamercolor{block body}{ bg=earthGreen!40}
\begin{block}{BlockTitle}
This is green
\end{block}
\end{frame}

To simplify this, I created a new command:

\newcommand{\myColoredBlock}[4][40]{
\begin{block}{#2}{
\setbeamercolor{block title}{bg=#3}
\setbeamercolor{block body}{bg=#3!#1}
#4
\end{block}

I then use the new command:

\begin{myColoredBlock}[35]{BlockTitle}{earthGreen}{
This is green
}\end{myColoredBlock}

But it isn't green! Clearly there is something wrong with my command.

Any ideas, anyone?

Thanks,

Dave

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

dmorgan
Posts: 5
Joined: Tue Nov 10, 2009 8:18 pm

Re: my \newcommand not working :-(

Post by dmorgan »

Figured it out. The colors need to be set before the block is entered. Duh!

\newcommand{\myColorBlock}[4][30]{
\setbeamercolor{block title}{bg= #3}
\setbeamercolor{block body}{bg= #3!#1}
\begin{block}{#2}
#4
\end{block}
}

Now it works fine!
Post Reply