
テキストの周囲にフレームを作成するために、単純な環境を作成 (コピー) しました。この環境は、mdframes
コンテンツをボックス化するために環境を使用し、changemargin
ボックスの左右に空白を追加するために使用される単純なマクロを使用します。
\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}
私の質問は、環境をコマンドのように使用できるかどうかです。
\Boxed{title}{content}
答え1
mdframed
実際には、コマンドが内部環境にラップされている場合は、コマンド内で環境を使用することが可能ですBoxedInternal
。
BoxedInternal
環境と\Boxed
マクロへのオプションの引数を使用して例を改善しました。
問題は、そのようなラッパー コマンドが一般的に役立つかどうかです。
\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}