How to change custom solution environment colors in Beamer theme?

Suppose I redefined the solution environment in Beamer using the following commands:

\let\solution\relax

\let\endsolution\relax

\newtheorem{solution}[theorem]{\translate{Solution}}


Then how can I change the colors of the title and body of the new solution environment?

MWE

\documentclass[t,xcolor=dvipsnames,fleqn,graphics]{beamer}

\usetheme{CambridgeUS}

\setbeamercovered{invisible}

\usepackage{framed,color}

\setbeamertemplate{theorems}[numbered]

\newcommand{\newblock}{}

\let\example\undefined

\theoremstyle{example}

\newtheorem{example}{\translate{Example}}

\let\solution\relax

\let\endsolution\relax

\newtheorem{solution}[theorem]{\translate{Solution}}

%

\begin{document}

%

\begin{frame}

\begin{example}

...

\end{example}

%

\begin{solution}

...

\end{solution}

%

\end{frame}

%

\end{document}


I want to change the color of "Solution 1" from green to say blue. How can I do this?

In fact, the primary reason I am redefining the solution environment is to control its counter through different frames. In particular, the command \addtocounter{solution}{1} does not work before a solution environment, so I am using now \addtocounter{theorem}{1} that does work, but unfortunately it deprived me from using a different color for the solution environment.

• Welcome! Please complete your code so we have a compilable example. We know very little about what your code does just from the snippet you've given us. We need something we can copy-paste-compile to emulate your situation and reproduce the issue you want help with. – cfr Oct 17 '15 at 22:30
• However, almost certainly the answer to your question is that you should not redefine the environment like that in the first place because, once you do so, you are essentially isolating it from Beamer's apparatus and colour management. However, without a complete example, this is just a guess really. – cfr Oct 17 '15 at 22:31
• @cfr The op wanted to ping you :-) – Johannes_B Oct 20 '15 at 10:37
• Your code gives a compilation error. I think we need an example which shows why you are doing this, too. Otherwise, any solution risks not accommodating whatever manipulation you are doing with the counters. I don't understand what you mean by that at the moment. – cfr Oct 21 '15 at 0:41
• @Johannes_B Thank you for passing the message on ;). – cfr Oct 21 '15 at 0:57

Is there any particular reason you can't just do this instead?

\documentclass[t]{beamer}
\usetheme{CambridgeUS}
\setbeamercovered{invisible}
\setbeamertemplate{theorems}[numbered]
\let\solution\relax
\newtheorem{solution}{\translate{Solution}}

\begin{document}
\begin{frame}
\begin{example}

...

\end{example}

\begin{solution}

...

\end{solution}
\end{frame}
\begin{frame}
\begin{example}

...

\end{example}

\begin{solution}

...

\end{solution}
\end{frame}
\end{document}


EDIT

It is perfectly possible to manipulate the counter used to number the solution environment. For example, if the second frame is changed as follows:

\end{frame}
\begin{frame}[fragile]
\begin{example}

...

\end{example}
If we want the next \verb|solution| environment to be numbered 58 rather than 2, we can add 56 to the counter:

\begin{solution}

...

\end{solution}
\end{frame}


then the output is as expected:

The reason this works is that

\let\solution\relax
\newtheorem{solution}{\translate{Solution}}


replaces the default solution environment, which does not have a distinct counter of its own, with one which does have such a counter. By default solution and example etc. all share a common sequence of numbers. What this trick does is to dissociate the solution environment from that sequence, so that it is incremented - and may be manipulated - independently.

• Once again I thank you for your posts. I did try your example code, but since I am using many overlays through my lecture slides, I can only control the counter of example environments through various sections using \addtocounter{example}{"#"}, but not the solution environments. I can see that your code provides a different color for the solution environment, but do you think you can control the counter of the solution environment when using some overlays through frames? – Dr. Kareem Elgindy Oct 21 '15 at 13:58
• @user90117 It is really not obvious what kind of control you want or need. Usually, a significant part of the point of these environments is that you don't have to worry about the numbering because it is automatic. Without some idea of why that doesn't work for you, it is anybody's guess what a solution might look like. I mean, you can say \addtocounter{solution}{56} before the second solution environment and it will be numbered 58 rather than 2. I'm not sure what further control would make sense. – cfr Oct 21 '15 at 20:54
• Dear Sir, I used \addtocounter{solution}{56} before the second solution environment as you mentioned and it worked :-). I mean the solution counter changed just like I wanted to. This is a little bit strange as I had a very large lecture slides file that I frequently tried to apply a similar command in it, but it never worked. Thanks Sir for your time and wonderful assistance :-). – Dr. Kareem Elgindy Oct 21 '15 at 22:15
• @Dr.KareemElgindy Great! I'm glad it worked. But... please don't call me 'sir'. It isn't appropriate. – cfr Oct 21 '15 at 22:53
• @Dr.KareemElgindy If the answer solves the problem, don't forget to consider accepting it by clicking on the greyed-out checkmark at the top left of the answer (underneath the vote counter). Thanks. – cfr Oct 21 '15 at 22:54