
Estoy muy cerca de conseguir la mdframed
configuración que quiero:
\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}
Dos preguntas:
¿Cómo hago el tamaño de fuente dentro del
mdframed
entorno\small
?¿Cómo puedo convertir esto en un entorno reutilizable, de modo que no tenga que comenzar y finalizar ambos
mdframed
entornostabbing
cada vez?
Respuesta1
Otro enfoque sin paquetes adicionales es definir un nuevo entorno; En el siguiente ejemplo, el entorno myenv
hace lo que usted quiere y tiene un argumento opcional para pasarle opciones 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}
Respuesta2
Úselo \mdfsetup{font=\small}
para agregar \small
a cada mdframed
entorno. Para encerrar un tabbing
entorno dentro de mdframed
, puede utilizar elxpatch
paquete y sus \xapptocmd
macros \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}
Una alternativa que prescinde xpatch
es emitir \surroundwithmdframed{tabbing}
en el preámbulo y utilizar tabbing
entornos en el cuerpo del documento. Tenga en cuenta que, al contrario de la solución anterior, esto no permitirá agregar argumentos opcionales a entornos individuales.
\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}
Salida para ambos ejemplos: