
Estou muito perto de conseguir a mdframed
configuração que desejo:
\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}
Duas questões:
Como faço para definir o tamanho da fonte dentro do
mdframed
ambiente\small
?Como posso transformar isso em um ambiente reutilizável, de modo que não seja necessário iniciar e encerrar os ambientes
mdframed
etabbing
todas as vezes?
Responder1
Outra abordagem sem pacotes adicionais é definir um novo ambiente; no exemplo a seguir, o ambiente myenv
faz o que você deseja e tem um argumento opcional para passar opções 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}
Responder2
Use \mdfsetup{font=\small}
para adicionar \small
a todos mdframed
os ambientes. Para incluir um tabbing
ambiente dentro de mdframed
, você pode usar oxpatch
pacote e seus \xapptocmd
e \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}
Uma alternativa dispensada xpatch
é emitir \surroundwithmdframed{tabbing}
no preâmbulo e utilizar tabbing
ambientes no corpo do documento. Observe que - ao contrário da solução acima - isso não permitirá adicionar argumentos opcionais a ambientes individuais.
\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}
Saída para ambos os exemplos: