Is it possible to specify a transparent background colour for the mdframed environment, so that anything which might be underneath will be visible?
2 Answers
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}
-
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
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)
\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
-
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}
– DanDec 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 :)– cmhughesDec 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.– DanDec 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 -
mdframed
can useTikZ
and with thetikzsetting
option you can pass arguments totikzset
. This way you should be able to change the opacity. I can't test this right now, but you can give it a try.fill opacity
in TikZ that should only affect the background.