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 looking to set a background color for my sidebars in the memoir class. Is there a way to do this? I am looking to add a light grey background to my side notes so that they stand out. Other options for making them stand out, beyond a simple background color will also be useful.

\documentclass{memoir}
\begin{document}

\setsidebars{*}{3cm}{*}{*}{*}{*}
\sidebar{ 
\textbf{Tip:} 

\smallskip
Here's a really useful trick to comparing fractions. It only works for two 
fractions at one time, but you can use it a few times if you have a few fractions.

\smallskip
You can cross-multiply and compare the products to see which fraction is larger.
}

\end{document}

Edit: So after putting in your solution, I am having a conflict with tikz boxes I have used. Here is a MWE with the issue. I figured this would be better than a screenshot. The solution is perfect for what I want, but I have a great many of these tikz boxes throughout the document.

\documentclass{memoir}
\usepackage{lipsum}
\usepackage{mdframed}
\usepackage{tikz}

% Sidebar
\makeatletter
\renewcommand{\sidebar}[1]{%
  \insert\sideins{%
\begin{mdframed}[
  backgroundcolor=gray!30,
  skipabove=0pt,
  innertopmargin=0pt,
  userdefinedwidth=\sidebarwidth,
  frametitle=Tip:,
  frametitlebelowskip=0pt]
    \hsize\sidebarwidth
    \@parboxrestore
    \def\baselinestretch{\m@m@footnote@spacing}%
    \m@mwhich@margin{\m@msidebar@margin}%
    \sidebarform\sidebarfont
    \splittopskip=\ht\strutbox
    \splitmaxdepth=\dp\strutbox % doesn't do anything useful
    \allowbreak
    \prevdepth=\dp\strutbox    % supersedes a "top-strut"
    \vskip-\parskip
    \parskip=\smallskipamount% optional
    #1%
    \ifvmode\else
      \unskip\@finalstrut\strutbox
    \fi\par
    \ifdim\prevdepth>\dp\strutbox \prevdepth=\dp\strutbox \fi
    \ifdim\prevdepth>99\p@
      \nobreak
      \vskip-\prevdepth
      \allowbreak
      \vskip\dp\strutbox
    \fi
    \vskip\sidebarvsep\end{mdframed}}%
}
\makeatother
% Tikz
\tikzset{
fancytitle/.style={fill=blue!15,draw=black,thick,text=black,rectangle,rounded corners},
lbox/.style= {draw=black,fill=black!5,thick,rectangle,rounded corners,inner xsep=7pt, inner ysep=15pt},
rbox/.style= {draw=black,fill=white,thick,rectangle,rounded corners,inner xsep=2pt, inner ysep=2pt}
}

\begin{document}


%         Tips Sidebar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
\setsidebars{*}{2cm}{*}{*}{*}{*}
% Parameters set with this command. Any command with `*' denotes no change.
% \setsidebars{⟨hsep⟩}{⟨width⟩}{⟨vsep⟩}{⟨topsep⟩}{⟨font⟩}{⟨height⟩}
\sidebar{ 

Here's a really useful trick to comparing fractions. It only works for two 
fractions at one time, but you can use it a few times if you have a few fractions.

You can cross-multiply and compare the products to see which fraction is larger.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
\begin{minipage}{\textwidth}
\begin{tikzpicture}[transform shape]
\node [lbox] (box) {
    \begin{minipage}{.4\textwidth}
        {
        \lipsum[1]
        }
    \end{minipage}
    };
\node[fancytitle,right=8pt] at (box.north west) {Lipsum};
\end{tikzpicture}
\hfill
\begin{tikzpicture}[transform shape]
\node [rbox] (box) {
    \begin{minipage}{.4\textwidth}
      { 
       \lipsum[1]
    }
    \end{minipage}
    };
    \node[fancytitle,right=8pt] at (box.north west) {Lipsum};
\end{tikzpicture}
\end{minipage}


\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

One possibility, using the mdframed package to add a colored frame; of course, using the features provided by the package, you can customize further the sidebars:

\documentclass{memoir}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}

\makeatletter
\renewcommand{\sidebar}[1]{%
  \insert\sideins{%
\begin{mdframed}[backgroundcolor=gray!30,skipabove=0pt]
    \hsize\sidebarwidth
    \@parboxrestore
    \def\baselinestretch{\m@m@footnote@spacing}%
    \m@mwhich@margin{\m@msidebar@margin}%
    \sidebarform\sidebarfont
    \splittopskip=\ht\strutbox
    \splitmaxdepth=\dp\strutbox % doesn't do anything useful
    \allowbreak
    \prevdepth=\dp\strutbox    % supersedes a "top-strut"
    \vskip-\parskip
    #1%
    \ifvmode\else
      \unskip\@finalstrut\strutbox
    \fi\par
    \ifdim\prevdepth>\dp\strutbox \prevdepth=\dp\strutbox \fi
    \ifdim\prevdepth>99\p@
      \nobreak
      \vskip-\prevdepth
      \allowbreak
      \vskip\dp\strutbox
    \fi
    \vskip\sidebarvsep\end{mdframed}}%
}
\makeatother

\begin{document}

\setsidebars{*}{3cm}{*}{*}{*}{*}
\lipsum[1-3]\sidebar{% 
\textbf{Tip:} 
\par\smallskip
Here's a really useful trick to comparing fractions. It only works for two 
fractions at one time, but you can use it a few times if you have a few fractions.
\par\smallskip
You can cross-multiply and compare the products to see which fraction is larger.}

\end{document}

enter image description here

Another advantage is that now you can automatically set the title "Tip:" and also set \parskip to be locally \smallskipamount, so you save a lot of manual work:

\documentclass{memoir}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}

\makeatletter
\renewcommand{\sidebar}[1]{%
  \insert\sideins{%
\begin{mdframed}[
  backgroundcolor=gray!30,
  skipabove=0pt,
  innertopmargin=0pt,
  userdefinedwidth=\sidebarwidth,
  frametitle=Tip:,
  frametitlebelowskip=0pt]
    \hsize\sidebarwidth
    \@parboxrestore
    \def\baselinestretch{\m@m@footnote@spacing}%
    \m@mwhich@margin{\m@msidebar@margin}%
    \sidebarform\sidebarfont
    \splittopskip=\ht\strutbox
    \splitmaxdepth=\dp\strutbox % doesn't do anything useful
    \allowbreak
    \prevdepth=\dp\strutbox    % supersedes a "top-strut"
    \vskip-\parskip
    \parskip=\smallskipamount% optional
    #1%
    \ifvmode\else
      \unskip\@finalstrut\strutbox
    \fi\par
    \ifdim\prevdepth>\dp\strutbox \prevdepth=\dp\strutbox \fi
    \ifdim\prevdepth>99\p@
      \nobreak
      \vskip-\prevdepth
      \allowbreak
      \vskip\dp\strutbox
    \fi
    \vskip\sidebarvsep\end{mdframed}}%
}
\makeatother

\begin{document}

\setsidebars{*}{3cm}{*}{*}{*}{*}
\lipsum[1-3]\sidebar{% 
Here's a really useful trick to comparing fractions. It only works for two 
fractions at one time, but you can use it a few times if you have a few fractions.
\par
You can cross-multiply and compare the products to see which fraction is larger.}

\end{document}

enter image description here

share|improve this answer
    
I have edited my question. The solution you provided doesn't quite mesh well with my page. I have included a MWE. Your solution is perfect however. –  Calhistorian Jun 28 '13 at 5:16
    
@Calhistorian of course they overlap, but this is not due to my code. You forgot to add \noindent, since the outer minipage starts a paragraph and it eill be indented; simply use \noindent\begin{minipage}{\textwidth}...\end{minipage}. –  Gonzalo Medina Jun 28 '13 at 19:32

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.