Memoir 中 \sidebar 的彩色背景

Memoir 中 \sidebar 的彩色背景

我想为sidebar回忆录类中的 s 设置背景颜色。有办法吗?我想为我的旁注添加浅灰色背景,以便它们脱颖而出。除了简单的背景颜色之外,其他使它们脱颖而出的选项也很有用。

\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}

编辑:所以在输入您的解决方案后,我使用过的 tikz 框发生了冲突。这是有关此问题的 MWE。我认为这比屏幕截图更好。该解决方案非常适合我想要的,但我在整个文档中都有很多这样的 tikz 框。

\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}

答案1

一种可能性是,使用mdframed包中添加彩色框架;当然,使用包提供的功能,您可以进一步自定义侧边栏:

\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}

在此处输入图片描述

另外一个优点是,现在你可以自动设置标题“提示:”并且也可以设置\parskip为本地的\smallskipamount,这样就节省了很多手动工作:

\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}

在此处输入图片描述

相关内容