我想定义一个新的“自定义description
”环境,假设my description
采用一个长度参数并产生通过以下代码实现的结果:
\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}
\begin{document}
Here's some text before the list.
\begin{description}[align=right, itemindent=0cm, leftmargin=\labelsep+3cm, font=\ttfamily]
\item [The first item] Math is so good!
\item [Here's the second one!] Let's do some math!
\end{description}
And here's something for after the list.
\end{document}
这里,leftmargin=3cm+\labelsep
是3cm
我想要传递“长度”参数的地方。
上述代码的输出如下所示:
另一件事:如果我还可以传递另一个参数来控制、等font
之间的值,那就非常方便了。\ttfamily
bfseries
答案1
只是
% definition
\NewDocumentEnvironment{my desp}{ m m }{%
\begin{description}[align=right, itemindent=0cm, leftmargin=\labelsep+#1, font=#2]
}{
\end{description}%
}
% usage
\begin{my desp}{3cm}{\ttfamily}
\item ...
\item ...
\end{my desp}
?
完整示例
\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}
\NewDocumentEnvironment{my desp}{ m m }{%
\begin{description}[align=right, itemindent=0cm, leftmargin=\labelsep+#1, font=#2]
}{
\end{description}%
}
\begin{document}
Here's some text before the list.
\begin{description}[align=right, itemindent=0cm, leftmargin=\labelsep+3cm, font=\ttfamily]
\item [The first item] Math is so good!
\item [Here's the second one!] Let's do some math!
\end{description}
And here's something for after the list.
\begin{my desp}{3cm}{\ttfamily}
\item [The first item] Math is so good!
\item [Here's the second one!] Let's do some math!
\end{my desp}
\end{document}