使用可选参数 Latex 中的新环境

问题描述 投票:0回答:1
我在 Latex 中定义了两个新环境(nmlist 和 nmlistf),如下所示。前者创建一个在第一行由 \paragraph 引入的标题的列表,后者创建一个从第一行开始没有任何标题的列表。我应该如何修改前者,以便除了它自己的输出之外,它还可以用于创建与后者类似的输出?感谢您的贡献!

这是代码:

\documentclass[final,3p,times]{elsarticle} \usepackage{enumitem} \newenvironment{nmlist}[1]{% list with title \paragraph{#1} \begin{enumerate}[align=parleft,itemsep=-4pt,labelwidth=20mm,leftmargin=22mm]} {\end{enumerate}} \newenvironment{nmlistf}{% list without title \begin{enumerate}[align=parleft,itemsep=-4pt,labelwidth=20mm,leftmargin=22mm]} {\end{enumerate}} \begin{document} % With a title at the first line and with a list starting at the second line \begin{nmlist}{Others} \item[{$a$}]{distances to x-axis}% \item[{$b$}]{distances to y-axis}% \end{nmlist} % Without a title and with a list starting at the first line \begin{nmlistf} \item[{$a$}]{distances to x-axis}% \item[{$b$}]{distances to y-axis}% \end{nmlistf} \end{document}
    
latex tex newenvironment
1个回答
0
投票
\documentclass[final,3p,times]{elsarticle} \usepackage{enumitem} \newenvironment{nmlist}[1][]{% list with title \ifstrempty{#1}{}{\paragraph{#1}}% \begin{enumerate}[align=parleft,itemsep=-4pt,labelwidth=20mm,leftmargin=22mm]} {\end{enumerate}} \begin{document} % With a title at the first line and with a list starting at the second line \begin{nmlist}[Others] \item[{$a$}] distances to x-axis \item[{$b$}] distances to y-axis \end{nmlist} % Without a title and with a list starting at the first line \begin{nmlist} \item[{$a$}] distances to x-axis \item[{$b$}] distances to y-axis \end{nmlist} \end{document}
    
© www.soinside.com 2019 - 2024. All rights reserved.