Page Layoutshaded environment "leaches" colour

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

shaded environment "leaches" colour

Post by jamesm »

Hi

I am using the shaded environment from the framed package to produce text with a coloured background. When I use shaded on its own, everything works fine, but if I embed it in another environment then the shadecolor I defined affects the text colour after the environment closes.

A minimal example:

Code: Select all

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{framed}

 \definecolor{shadecolor}{named}{Salmon}
 
\newenvironment{example}%
 {\noindent\raggedright 
     \begin{shaded}\color{Blue}\textbf{Example: }}{ 
  \end{shaded}}

\setlength{\parskip}{12pt}

\begin{document}

Here's a sentence in the default colour (black)

\begin{shaded}
Here's some text in the shaded environment with salmon background. 
\end{shaded}

This sentence is also in the default colour (black)

\begin{example}
This example should have a Salmon background and blue text.  Seems to work nicely! 
\end{example}

This is more text which should be black, but is salmon instead!  Where has that come from?

\end{document}
Any suggestions for what I'm doing wrong? I've seen several examples online which embed shaded in another environment, but no mention of this issue.

Thanks
James
minitest-shaded.pdf
Here's the pdf output.
(8.47 KiB) Downloaded 434 times

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

shaded environment "leaches" colour

Post by cgnieder »

I must admit I'm not sure what's happening here. I have an alternative suggestion, though: use mdframed instead of framed.

Code: Select all

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{mdframed}

\colorlet{example}{Salmon}
\colorlet{exampletext}{Blue}
 
\newenvironment{example}
  {
    \raggedright
    \color{exampletext}\textbf{Example: }%
  }{}
\surroundwithmdframed[
  hidealllines=true,
  backgroundcolor=example
]{example}

% don't do this! Use the `parskip' package if you must have paragraph
% skips. setting the length manually has effects in places where it is
% unexpected and not wanted.
% \setlength{\parskip}{12pt}

\usepackage{lipsum} % dummy text

\begin{document}

Here's a sentence in the default colour (black) \lipsum[4]

\begin{example}
  This example should have a Salmon background and blue text.  Seems to work
  nicely! \lipsum[4]
\end{example}

Here's a sentence in the default colour (black) \lipsum[4]

\end{document}
framed.png
framed.png (77.04 KiB) Viewed 12172 times
Regards
site moderator & package author
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

Re: shaded environment "leaches" colour

Post by jamesm »

Thanks Clemens - I didn't know about that package.

Still - I'd like to know how to fix the first problem.

James

ps I also didn't know about the parskip package!

embarrassment: title should be "leaches" not "leeches" !!
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

shaded environment "leaches" colour

Post by cgnieder »

jamesm wrote:Still - I'd like to know how to fix the first problem.
I'll see what I can find out :)

I'd still recommend mdframed which is an actively maintained package with lots of bells and whistles for customization.
jamesm wrote:embarrassment: title should be "leaches" not "leeches" !!
I edited the title :)

Regards
site moderator & package author
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

shaded environment "leaches" colour

Post by jamesm »

Thanks again - I'll have a good look at the mdframed package.

James
Post Reply