
Criei (copiei) um ambiente simples para criar uma moldura em torno de um trecho de texto. O ambiente usa o mdframes
ambiente para encaixotar o conteúdo e uma macro simples changemargin
que é usada para adicionar algum espaço em branco à esquerda e à direita da caixa.
\documentclass{article}
\usepackage[utf8]{inputenc}
% mdframe: put a certain amount of text in a box
\usepackage[framemethod=default]{mdframed}
\usepackage{showexpl}
\mdfdefinestyle{exampledefault}{
rightline=true,
innerleftmargin=10,
innerrightmargin=10,
frametitlerule=true,
frametitlerulecolor=black,
frametitlebackgroundcolor=white,
frametitlerulewidth=1pt,
}
% macro to change margins
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
% custom environment
\newenvironment{Boxed}[1]
{
\begin{changemargin}{2cm}{2cm}
\begin{mdframed}[style=exampledefault, frametitle={#1}]
}
{
\end{mdframed}
\end{changemargin}
}
\usepackage{lipsum} % add some text
\begin{document}
\lipsum
\begin{Boxed}{I'm the title}
I'm the content. I've a nice frame around me.
\end{Boxed}
\end{document}
Este é o resultado. Funciona perfeitamente.
Minha pergunta é: posso usar meu ambiente como um comando?
\Boxed{title}{content}
Responder1
Na verdade, é possível usar um mdframed
ambiente dentro de um comando se ele estiver encapsulado em um BoxedInternal
ambiente interno.
Melhorei o exemplo com um argumento opcional para BoxedInternal
ambiente e \Boxed
macro.
A questão é se tais comandos wrapper são úteis em geral.
\documentclass{article}
\usepackage[xcolor]{mdframed}
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist
\mdfdefinestyle{exampledefault}{backgroundcolor=yellow!10!white}
\newenvironment{BoxedInternal}[2][]
{%
\begin{changemargin}{0cm}{0cm}%
\begin{mdframed}[style=exampledefault, frametitle={#2},#1]
}{%
\end{mdframed}%
\end{changemargin}%
}
\newcommand{\Boxed}[3][]{%
\begin{BoxedInternal}[#1]{#2}
#3
\end{BoxedInternal}%
}
\begin{document}
\Boxed{Foo}{Foobar}
\end{document}