回忆录盒装示例环境

回忆录盒装示例环境

Memoir 的手册中有这样的例子带标题的框架环境。我想知道如何添加计数器?比如,模仿 AMS 定理环境。任何更好的方法在回忆录中实现这一点也受到欢迎。

 \documentclass[12pt,twoside,openright,a4paper]{memoir}
 \newcommand{\FrameTitle}[2]{%
 \fboxrule=\FrameRule \fboxsep=\FrameSep
 \fbox{\vbox{\nobreak \vskip -0.7\FrameSep
 \rlap{\strut#1}\nobreak\nointerlineskip% left justified
 \vskip 0.7\FrameSep
 \hbox{#2}}}}
 \newenvironment{framewithtitle}[2][\FrameFirst@Lab\ (cont.)]{%
 \def\FrameFirst@Lab{\textbf{#2}}%
 \def\FrameCont@Lab{\textbf{#1}}%
 \def\FrameCommand##1{%
 \FrameTitle{\FrameFirst@Lab}{##1}}%
 \def\FirstFrameCommand##1{%
 \FrameTitle{\FrameFirst@Lab}{##1}}%
 \def\MidFrameCommand##1{%
 \FrameTitle{\FrameCont@Lab}{##1}}%
 \def\LastFrameCommand##1{%
 \FrameTitle{\FrameCont@Lab}{##1}}%
\MakeFramed{\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}
\begin{document}
\begin{framewithtitle}{Test} This is a test.
\end{framewithtitle}
 \end{document}

答案1

我建议你使用mdframed或者tcolorbox包;两者都为您提供了一个简单的键值接口来定义装饰定理类结构,这些结构将自动包含计数(并且易于控制所使用的计数器)。

在下面的示例代码中,我展示了以下环境之间的比较赫伯特提供his answer使用上面提到的软件包构建的其他五个环境。使用这些软件包,您可以轻松制作出您想要的精美装饰(在我的示例中,我限制为某种“朴素”的结构,但您可以轻松尝试不同的风格):

在此处输入图片描述

代码:

 \documentclass[12pt,twoside,openright,a4paper]{memoir}
 \usepackage[framemethod=tikz]{mdframed}
 \usepackage[many]{tcolorbox}
 \usepackage{amsthm}


 \newtcbtheorem[number within=chapter]{testiv}{Test}{   
   outer arc=0pt,arc=0pt}{tha}
 \newtcbtheorem[number within=chapter]{testv}{Test}{   
   outer arc=0pt,
   arc=0pt,
   colback=white,
   colframe=black,
   colbacktitle=white,
   titlerule=0pt,
   fonttitle=\normalcolor\itshape}{thb}

 \newmdtheoremenv{testi}{Test}[chapter]
 \newmdtheoremenv[
   backgroundcolor=gray!50
 ]{testii}{Test}[chapter]
 \theoremstyle{remark}
 \newmdtheoremenv{testiii}{Test}[chapter]

 \newcounter{FrameCnt} \setcounter{FrameCnt}{0}
 \newcommand{\FrameTitle}[2]{%
   \fboxrule=\FrameRule \fboxsep=\FrameSep
   \fbox{\vbox{\nobreak \vskip -0.7\FrameSep
   \rlap{\strut#1}\nobreak\nointerlineskip% left justified
   \vskip 0.7\FrameSep
   \hbox{#2}}}}
 \newenvironment{framewithtitle}[2][\FrameFirst@Lab\ (cont.)]
   {\refstepcounter{FrameCnt}%
    \def\FrameFirst@Lab{\textbf{#2~\theFrameCnt}}%
    \def\FrameCont@Lab{\textbf{#1}}%
    \def\FrameCommand##1{\FrameTitle{\FrameFirst@Lab}{##1}}%
    \def\FirstFrameCommand##1{\FrameTitle{\FrameFirst@Lab}{##1}}%
    \def\MidFrameCommand##1{\FrameTitle{\FrameCont@Lab}{##1}}%
    \def\LastFrameCommand##1{\FrameTitle{\FrameCont@Lab}{##1}}%
    \MakeFramed{\advance\hsize-\width \FrameRestore}}
  {\endMakeFramed}

\begin{document}
\chapter{Test chapter}

Using your environmet:
\begin{framewithtitle}{Test} 
This is a test.
\end{framewithtitle}

\noindent Using \texttt{mdframed}:
\begin{testi}
This is a test.
\end{testi}

\begin{testii}
This is a test.
\end{testii}

\begin{testiii}
This is a test.
\end{testiii}

\noindent Using \texttt{tcolrbox}:
\begin{testiv}{}{}
This is a test.
\end{testiv}

\begin{testv}{}{}
This is a test.
\end{testv}

\end{document}

作为艾伦提到过his comment,可以在以下答案中找到更多丰富多彩的选项TikZ-用于构建定理、引理、命题等的漂亮盒子我在这个网站上还有许多其他的答案。

答案2

\documentclass[12pt,twoside,openright,a4paper]{memoir}
 \newcounter{FrameCnt} \setcounter{FrameCnt}{0}
 \newcommand{\FrameTitle}[2]{%
   \fboxrule=\FrameRule \fboxsep=\FrameSep
   \fbox{\vbox{\nobreak \vskip -0.7\FrameSep
   \rlap{\strut#1}\nobreak\nointerlineskip% left justified
   \vskip 0.7\FrameSep
   \hbox{#2}}}}
 \newenvironment{framewithtitle}[2][\FrameFirst@Lab\ (cont.)]
   {\refstepcounter{FrameCnt}%
    \def\FrameFirst@Lab{\textbf{#2~\theFrameCnt}}%
    \def\FrameCont@Lab{\textbf{#1}}%
    \def\FrameCommand##1{\FrameTitle{\FrameFirst@Lab}{##1}}%
    \def\FirstFrameCommand##1{\FrameTitle{\FrameFirst@Lab}{##1}}%
    \def\MidFrameCommand##1{\FrameTitle{\FrameCont@Lab}{##1}}%
    \def\LastFrameCommand##1{\FrameTitle{\FrameCont@Lab}{##1}}%
    \MakeFramed{\advance\hsize-\width \FrameRestore}}
  {\endMakeFramed}
\begin{document}
\begin{framewithtitle}{Test\label{foo}} This is a test.
\end{framewithtitle}

As seen in Frame \ref{foo} \ldots
\end{document} 

在此处输入图片描述

相关内容