1

I would be able to do something like the following:

Instead of having the following, where I repeat the same code many many times:

\documentclass{article}
\usepackage{enumerate}
\newenvironment{enum1}{\begin{enumerate}[1.]}{\end{enumerate}}
\newenvironment{enuma}{\begin{enumerate}[a.]}{\end{enumerate}}
...

I would like to be able to "automate" it somewhat, eg.:

\documentclass{article}
\newcommand{\newEnum}[1]{\newenvironment{enum#1}{\begin{enumerate}[#1.]}{\end{enumerate}}
\newEnum{1}
\newEnum{a}
...

Of course, this doesn't compile, or I wouldn't be here asking.

Is there a way to do this, or am I stuck copy and pasting and making the necessary changes?

1
  • 2
    You're short a close brace } in your definition of \newEnum. Apart from that, it works. – Werner Sep 24 '14 at 20:18
5

For lists I'd recommend you use the enumitem package and use the newlist facility that is built in.

enter image description here

If you have many of these you could use

\newcommand{\DefineNewList}[3]{%
    % #1 = name
    % #2 = max depth
    % #3 = label
    \newlist{#1}{enumerate}{#2}
    \setlist[#1]{label*=#3}
}%

but I don't see much value in that.

Code:

\documentclass{article}
\usepackage{enumitem}

\newlist{enumOne}{enumerate}{2}
\setlist[enumOne]{label*=\arabic*.}

\newlist{enumA}{enumerate}{2}
\setlist[enumA]{label*=\alph*.}

\begin{document} 

\begin{enumOne}
    \item First item in enumOne
    \item Second item in enumOne
\end{enumOne}

\begin{enumA}
    \item First item in enumA
    \item Second item in enumA
\end{enumA}

\end{document} 

Code Repeated Usage:

\documentclass{article}
\usepackage{enumitem}

\newcommand{\DefineNewList}[3]{%
    % #1 = name
    % #2 = max depth
    % #3 = label
    \newlist{#1}{enumerate}{#2}
    \setlist[#1]{label*=#3}
}%

\DefineNewList{enumOne}{2}{\arabic*.}
\DefineNewList{enumA}{2}{\alph*.}

\begin{document} 

\begin{enumOne}
    \item First item in enumOne
    \item Second item in enumOne
\end{enumOne}

\begin{enumA}
    \item First item in enumA
    \item Second item in enumA
\end{enumA}

\end{document} 
1
\documentclass{article}
\usepackage{enumerate}
\newcommand\newEnum[1]{%
  \newenvironment{enum#1}{\enumerate[#1.]}{\endenumerate}}
\newEnum{1}
\newEnum{a}
\begin{document}

\begin{enumerate}
\item foo
\item bar
\end{enumerate}

\begin{enum1}
\item foo
\item bar
\end{enum1}

\begin{enuma}
\item foo
\item bar
\end{enuma}

\end{document}

However, using package enumitem has some more possibilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.