1

I have the following environment.

\newenvironment{myenv}[0]{%
  \begin{enumerate}[label = {My Label}]%
}{
  \end{enumerate}
}

I would like to have an optional argument for myenv that is a list of options passed into the enumerate environment.

For example, something like,

\begin{myenv}{noitemsep, nolistsep, label = {New Label}}
  ...
\end{myenv}

would produce,

\begin{enumerate}[label = {New Label}, noitemsep, nolistsep]
...
\end{enumerate}

Note that label was overridden, but this functionality is not necessary.

Is something like this possible?

1 Answer 1

1

This is definitely possible. Since you're using enumerate, I'd suggest not to use a fixed label like My Label. Here's how to do it:

enter image description here

\documentclass{article}

\usepackage{enumitem}

\newenvironment{myenv}[1][]{%
  \begin{enumerate}[
    label=\arabic*.,ref=\arabic*,% Default enumerate options
    #1% Any additional content (could override default options)
  ]
}{%
  \end{enumerate}
}

\begin{document}

Some content before \verb|myenv| (no optional parameter).
\begin{myenv}
  \item First
\end{myenv}
Some content after \verb|myenv|.

Some content before \verb|myenv| (with an optional parameter).
\begin{myenv}[noitemsep, nolistsep, label={N\arabic*.}, ref={N\arabic*}]
  \item First
\end{myenv}
Some content after \verb|myenv|.

\end{document}

You can also do this natively via a new list:

\usepackage{enumitem}

\newlist{myenv}{enumerate}{1}
\setlist[myenv,1]{% Default options for myenv
  label=\arabic*.,
  ref=\arabic*
}
1
  • Thanks for your answer. I did exactly what you did before posting this, and now realize it was not working because of something else.
    – Oliver
    Apr 1, 2022 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .