Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to place a background that extends the entire page width and whose height depends on the height of the environment contained. For example, the following code provides something to what I am looking for:

\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb,calc}
\usepackage{framed}
\setlength{\parindent}{0pt}


\newenvironment{test}[1]{%
\def\FrameCommand{\fboxsep=\FrameSep\colorbox{green!15}}%
\MakeFramed {\advance\hsize -\width \FrameRestore}}%
{\endMakeFramed}

\begin{document}
\begin{test}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibu-
lum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris.
Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et ne-
tus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus
rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu
tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Cur-
abitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
\end{test}

\end{document}

enter image description here

But of course this frame only extends to the text width. I want to cover the entire margins on both sides while keeping whatever environment within the \textwidth. I was thinking of using the TikZ or its affiliate the background package. I would reall appreciate solutions within the scope of the framed package, mdframed package, TikZ or background package.

share|improve this question
3  
Why not mdframed? –  egreg Feb 14 '13 at 16:51
1  
@egreg Yeah why not? I would love that as well. –  azetina Feb 14 '13 at 16:54

2 Answers 2

Use mdframed and give margins in wide excess, so that this will work even in twosided printing:

\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{mdframed}
\setlength{\parindent}{0pt}

\usepackage{lipsum}


\newmdenv[skipabove=\topsep,skipbelow=\topsep,
  leftmargin=-10cm,rightmargin=-10cm,
  innerleftmargin=10cm,innerrightmargin=10cm,
  innertopmargin=\fboxsep,innerbottommargin=\fboxsep,
  backgroundcolor=green!15,
  hidealllines=true,
]{test}

\begin{document}
\lipsum[2]

\begin{test}
\lipsum[1]
\end{test}

\lipsum[3]

\end{document}

enter image description here

share|improve this answer
    
How can you increase the width of the \FrameCommand by using the framed package. Just curious. Are there any parameters that can be added to increase it horizontally and vertically? –  azetina Feb 14 '13 at 19:24
1  
@azetina I haven't the slightest idea. –  egreg Feb 14 '13 at 20:16

After consulting with the author of the framed package, the following code generates the desired result:

\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{framed}
\setlength{\parindent}{0pt}

\usepackage{lipsum}

\newenvironment{test}[1][green!15]{%
\def\FrameCommand##1{%
\setlength\leftmargin{1in+
    \ifodd\value{page}\oddsidemargin\else\evensidemargin\fi}%
    \setlength\rightmargin{\paperwidth-\textwidth-\leftmargin}%
    %
    \hspace{-\leftmargin}%
    \colorbox{#1}{%
    \hspace{-\fboxsep}%
    \hspace{\leftmargin}%
    ##1%
    \hspace{\rightmargin}%
    \hspace{-\fboxsep}%
    }%
    \hspace{-\rightmargin}%
    }
\MakeFramed {\advance\hsize -\width \FrameRestore}}%
{\endMakeFramed}
\begin{document}
\begin{test}
\lipsum[1-2]
\end{test}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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