1

I want to place a framed box with some code in a shaded box but for some reason the frame is not showing up. How can I get the frame to show up?

\documentclass{memoir}
\usepackage{framed}
\usepackage{color}
\definecolor{shadecolor}{rgb}{0.93,0.93,0.93}
\begin{document}
\begin{shaded}
\trivlist\item\ignorespaces%
Lorem ipsum 

  \begin{framed}
    \begin{minipage}[h]{0.9\linewidth}
    \begin{verbatim}
foo bar
    \end{verbatim}
    \end{minipage}
  \end{framed}

cit dolor
\endtrivlist
\end{shaded}
\end{document}

enter image description here

  • 1
    Do you mean framed box with some shade or framed box with in a shaded box ? – MadyYuvi Jul 28 '17 at 8:40
  • Framed box within a shaded box. See the example code. – jonalv Jul 28 '17 at 8:59
1

I can not answer why frame doesnt work as expected, but below is a code that gives what you want. Just use mdframed instead of framed.

\documentclass{memoir}
\usepackage{mdframed}
\usepackage{color}
\definecolor{shadecolor}{rgb}{0.93,0.93,0.93}
\begin{document}
\begin{shaded}
\trivlist\item\ignorespaces%
Lorem ipsum 

  \begin{mdframed}[backgroundcolor=shadecolor]
    \begin{minipage}[h]{0.9\linewidth}
    \begin{verbatim}
foo bar
    \end{verbatim}
    \end{minipage}
    \end{mdframed}
cit dolor
\endtrivlist
\end{shaded}
\end{document}
1

Here is a verbatimbox approach.

\documentclass{memoir}
\usepackage{verbatimbox}
\usepackage{color}
\definecolor{shadecolor}{rgb}{0.93,0.93,0.93}
\begin{document}
\begin{shaded}
\trivlist\item\ignorespaces%
Lorem ipsum 

\begin{minipage}[b]{0.9\linewidth}
\begin{verbbox}
foo bar
\end{verbbox}
\fbox{\theverbbox}
\end{minipage}

cit dolor
\endtrivlist
\end{shaded}
\end{document}

enter image description here

If one wanted the framed box to stretch across the full area, then replace \fbox{\theverbbox} with \fbox{\makebox[\linewidth][l]{\theverbbox}} to get:

enter image description here

If one upgrades to the xcolor package, then an invocation of

\fcolorbox{red}{shadecolor!50}{\makebox[\linewidth][l]{\theverbbox}}

results in

enter image description here

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.