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

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}

enter image description here


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:

enter image description here