15

Is it possible to specify a transparent background colour for the mdframed environment, so that anything which might be underneath will be visible?

3
  • 4
    mdframed can use TikZ and with the tikzsetting option you can pass arguments to tikzset. This way you should be able to change the opacity. I can't test this right now, but you can give it a try. Dec 14, 2011 at 16:04
  • I only want the background to be transparent, not the borders or text. Is this possible using 'tikzset' ?
    – Dan
    Dec 14, 2011 at 16:43
  • 1
    Like I said, I can't test this right now. But there is a fill opacity in TikZ that should only affect the background. Dec 14, 2011 at 17:04

2 Answers 2

16

You must set the opacity to the whole environment.

\documentclass{article}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\usepackage{background}
\SetBgContents{top secret}
\SetBgColor{red}
%  \tikzset{mdfbackground/.style={fill=red,opacity=0.1,draw=green}}%
\newmdenv[tikzsetting={draw=blue,fill=red,},settings={\tikzset{every picture/.style={opacity=0.6}}}]{myenvironment}
\begin{document}
\BgThispage

\begin{tikzpicture}
\draw[blue,fill] (0,0) rectangle (8,4);
\node[text width=8cm] {\lipsum[1]};
\end{tikzpicture}

\begin{myenvironment}
\lipsum[1]
\end{myenvironment}
\end{document}

1
  • That makers the text and the frame also transparent. But the solution suggested by Philippe Goutet in a comment to another answer seems to work. Dec 18, 2011 at 20:58
14
+50

As mentioned in the comments, you can set mdframed to use TikZ. Here is a MWE that sets the fill opacity to 0.5; you can tweak it to whatever you would like between 0 (fully transparent, or invisible) and 1 (fully opaque, or solid)

screenshot

\documentclass{article}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newmdenv[tikzsetting={draw=blue,fill=red,fill opacity=0.5}]{myenvironment}

\begin{document}

\begin{myenvironment}
\lipsum[1]
\end{myenvironment}
\end{document}

Following @PhilippeGoutet's comment, you can use

\newmdenv[tikzsetting={draw=blue,fill=red,fill opacity=0.5},backgroundcolor=none]{myenvironment}

which gives

screenshot

7
  • Thanks, but that doesn't give me what I want. If this box overlays any other text, I want to be able to see it. eg. \documentclass{article} \usepackage{tikz} \usepackage[framemethod=tikz]{mdframed} \usepackage{lipsum} \newmdenv[tikzsetting={draw=blue,fill=red,fill opacity=0.5}]{myenvironment} \begin{document} \vtop to 0pt{\LARGE Some text underneath} \begin{myenvironment} \lipsum[1] \end{myenvironment} \end{document}
    – Dan
    Dec 16, 2011 at 14:23
  • @Dan I see the problem now- note that this wasn't completely obvious in your original question; this would have been a good place for a MWE. I'll work on your updated problem :)
    – cmhughes
    Dec 16, 2011 at 16:56
  • Yes, my apologies, you are right, I should have provided an example, but I had no idea how to achieve the effect. I very much appreciate your efforts to help.
    – Dan
    Dec 17, 2011 at 19:01
  • 6
    @Dan: use \newmdenv[tikzsetting={fill=red,fill opacity=0.5},backgroundcolor=none]{myenvironment} Dec 18, 2011 at 18:47
  • @PhilippeGoutet Thank you very much, see my edit :)
    – cmhughes
    Dec 18, 2011 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.