Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.