# change color in shaded environment

I'd like to switch color in a shaded environment (package framed.sty). Something like that :

\definecolor{shadecolor}{1 0 0}
This line is red

\switch{yellow} and this line is yellow

Back to red !


or an environmented version :

\begin{shaded}
This line is red

\begin{switch}
and this line in yellow
\end{switch}

Back to red !


I tried to change the \FrameCommand in the definition of the \switch macro but it doesn't work (I don't exactly understand when the \FrameCommand is called).

Ideally, I'd like to stick with the framed package, but if another is more suitable, I'll go for it!

• Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. – user30471 Nov 2 '18 at 21:27

I don't know the framed package and the manual is not so revealing. As I could not get your code snippets to compile I recommend using tcolorbox, which is a much more powerful package for this sort of thing - another option that you could consider is mdframed.

I am not entirely sure what effect you want, but using nested tcolorbox environments with the default settings, except for background colour, gives:

With a little more effort you can remove the indentation, the frames and the rounded corners:

The tcolorbox manual is very comprehensive and readable.

Here is the full code for the images above:

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}

Standard nested boxes using tcolorbox:

\begin{tcolorbox}[colback=red!]
This line is red

\begin{tcolorbox}[colback=yellow!]
and this line in yellow
\end{tcolorbox}

Back to red !
\end{tcolorbox}

With a little more effect we can remove frames etc:

\begin{tcolorbox}[colback=red!,boxrule=0mm,sharp corners]
This line is red

\begin{tcolorbox}[colback=yellow!, boxrule=0mm,
grow to left by=5mm,
grow to right by=5mm,
sharp corners]
and this line in yellow
\end{tcolorbox}

Back to red !
\end{tcolorbox}

\end{document}

• Seems to be the way to go, and wanted to give ot a try yesterday. My MikTeX being a little out-of-date, I made an update to get the latest version in the package manager. Unfortunately, I can't compile anything since... – T. Tournesol Nov 8 '18 at 13:55