我非常接近得到mdframed
我想要的设置:
\documentclass[a4paper,10pt]{book}
\usepackage[paper=a4paper,twoside=true,lmargin=4cm,
rmargin=4cm,bindingoffset=0cm]{geometry}
\usepackage{mdframed}
\begin{document}
\noindent Surrounding text.
\begin{mdframed}
\begin{tabbing}
some great \=code\\
\>next line
\end{tabbing}
\end{mdframed}
\noindent Surrounding text.
\end{document}
两个问题:
如何在
mdframed
环境中调整字体大小\small
?我怎样才能将其转变为可重复使用的环境,以便我不必每次都开始和结束
mdframed
和环境?tabbing
答案1
另一种不需要额外软件包的方法是定义一个新环境;在下面的例子中,该环境myenv
执行您想要的操作,并且有一个可选参数来传递选项mdframed
:
\documentclass[a4paper,10pt]{book}
\usepackage[framemethod=tikz]{mdframed}
\newenvironment{myenv}[1][]
{\begin{mdframed}[font=\small,#1]\begin{tabbing}}
{\end{tabbing}\end{mdframed}}
\begin{document}
\noindent Surrounding text.
\begin{myenv}
some great \=code\\
\>next line
\end{myenv}
\noindent Surrounding text.
\begin{myenv}[backgroundcolor=red!20]
some great \=code\\
\>next line
\end{myenv}
\end{document}
答案2
使用\mdfsetup{font=\small}
添加\small
到每个mdframed
环境。要将tabbing
环境包含在 中mdframed
,可以使用xpatch
包及其\xapptocmd
宏\xpretocmd
。
\documentclass[a4paper,10pt]{book}
\usepackage{mdframed}
\mdfsetup{font=\small}
\usepackage{xpatch}
\xapptocmd{\mdframed}{\begin{tabbing}}{}{}
\xpretocmd{\endmdframed}{\end{tabbing}}{}{}
\begin{document}
\noindent Surrounding text.
\begin{mdframed}
some great \=code\\
\>next line
\end{mdframed}
\noindent Surrounding text.
\end{document}
另一种方法是在前言中xpatch
发出并在文档正文中使用环境。请注意——与上述解决方案相反——这不允许向单个环境添加可选参数。\surroundwithmdframed{tabbing}
tabbing
\documentclass[a4paper,10pt]{book}
\usepackage{mdframed}
\surroundwithmdframed[font=\small]{tabbing}
\begin{document}
\noindent Surrounding text.
\begin{tabbing}
some great \=code\\
\>next line
\end{tabbing}
\noindent Surrounding text.
\end{document}
两个示例的输出: