# Making the font size smaller in this mdframed, and turning into a reusable environment

I am very close to getting the mdframed setting that I want:

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


Two questions:

1. How do I make the font size within the mdframed environment \small?

2. How can I turn this into a reusable environment, such that I won't have to begin and end both the mdframed and tabbing environments every time?

-

Another approach without additional packages is to define a new environment; in the following example, the environment myenv does what you want and hasan optional argument to pass options to 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}


-

Use \mdfsetup{font=\small} to add \small to every mdframed environment. To enclose a tabbing environment within mdframed, you may use the xpatch package and its \xapptocmd and \xpretocmd macros.

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


An alternative that does without xpatch is to issue \surroundwithmdframed{tabbing} in the preamble and to use tabbing environments in the document body. Note that -- contrary to the above solution -- this won't allow to add optional arguments to individual environments.

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


Output for both examples:

-