Text FormattingEnumitem's resume in newenvironment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

Enumitem's resume in newenvironment

Post by Sleft »

Hello,

I need help getting enumitem's resume option to work with newenvironment. Here's an example where the first two enumeration's resume option is not working but the last two is working:

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\newenvironment{pvn}[1]
  {\begin{enumerate}[resume,label=#1\arabic*]}
  {\end{enumerate}}

\begin{document}

Not working:
\begin{pvn}{d}
\item bla
\end{pvn}

\begin{pvn}{d}
\item bla % I want this label to be 'd2'
\end{pvn}

Working:
\begin{enumerate}[resume,label=d\arabic*]
\item bla
\end{enumerate}

\begin{enumerate}[resume,label=d\arabic*]
\item bla
\end{enumerate}

\end{document}
What I want is the first two enumeration's resume to work.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Enumitem's resume in newenvironment

Post by frabjous »

Could you use \newlist and \setlist instead? Below is close to what you want, but uses a slightly different syntax. (E.g., if you want to change "d" to something else, you'd need to use \setpvnl.)

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\newlist{pvn}{enumerate}{1}
\newcommand{\pvnl}{d}
\setlist[pvn]{resume,label={\pvnl\arabic*}}

\newcommand{\setpvnl}[1]{\renewcommand{\pvnl}{#1}}

\begin{document}

\begin{pvn}
\item bla
\end{pvn}

\setpvnl{e}
\begin{pvn}
\item bla % I want this label to be 'd2'
\end{pvn}

\end{document}
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

Enumitem's resume in newenvironment

Post by Sleft »

Thanks for your reply.

I want the number of the label to have a different counter for every unique letter. With your solution the counter is not reset when I change from label prefix 'd' to 'e'.

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\newlist{pvn}{enumerate}{1}
\newcommand{\pvnl}{d}
\setlist[pvn]{resume,label={\pvnl\arabic*}}

\newcommand{\setpvnl}[1]{\renewcommand{\pvnl}{#1}}

\begin{document}

\begin{pvn}
\item bla
\item bla
\end{pvn}

\setpvnl{e}
\begin{pvn}
\item bla % I want this label to be 'e1'
\end{pvn}
bla
\begin{pvn}
\item bla % I want this label to be 'e2'
\end{pvn}

\end{document}
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Enumitem's resume in newenvironment

Post by frabjous »

Can you create separate lists for each one, or do you not know ahead of time how/many and what form these could take?

Code: Select all

\documentclass{article}
\usepackage{enumitem}

\newlist{pvnd}{enumerate}{1}
\setlist[pvnd]{resume,label=d\arabic*}
\newlist{pvne}{enumerate}{1}
\setlist[pvne]{resume,label=e\arabic*}

\begin{document}

\begin{pvnd}
\item bla
\item bla
\end{pvnd}

\begin{pvne}
\item bla % I want this label to be 'e1'
\end{pvne}
bla
\begin{pvne}
\item bla % I want this label to be 'e2'
\end{pvne}

\end{document}
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

Re: Enumitem's resume in newenvironment

Post by Sleft »

Ideally I want a solution that is not depending on if I know ahead of time what labels I need. Thanks for your suggestion though. That is the best I've got yet.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Enumitem's resume in newenvironment

Post by frabjous »

You could also use my first suggestion with [start=1] after \begin{pvn} when you begin a new series. But I know that's not pretty. It does seem like there should be a solution to this. I'll think about whether I can come up with something else.
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

Re: Enumitem's resume in newenvironment

Post by Sleft »

Thanks. I'm afraid controlling the counter by hand as in \begin{pvn}[start=1] is not an option since I want the series to be able to overlap with a result such as the following (with or without running text between the list items):
d1 bla
d2 bla
e1 bla
d3 bla
e2 bla

I'm using the labels to list important propositions by different authors so I can make cross-references to them easily. The letters, 'd' and 'e' in the example, are to denote the first letter in the authors surname.
bootcut
Posts: 6
Joined: Fri Mar 02, 2012 6:07 pm

Enumitem's resume in newenvironment

Post by bootcut »

I may have figured out a way around the resume option not working within the newenvironment. I'm trying to make a survey, and created a new environment to quickly create survey questions and answers. I at first was running into similar problems with resume option and \newenvironment.

Code: Select all

\documentclass{article}

\usepackage{enumitem} 
\usepackage{amssymb}

\newlist{questions}{enumerate}{1}
\setlist[questions]{resume, label=\bf\arabic*.}

\newenvironment{question}[1]
{\begin{questions}%[resume, label=\bf\arabic*.]
  \item \textbf{#1}   % #1 variable is the survey question 
  \begin{itemize}\renewcommand{\labelitemi}{\large $\square$}}
  % all \item in the question environment will be the answer options.
{ \end{itemize} 
\end{questions}}

\begin{document}

% DOES NOT RESUME
\begin{question}{Question environment correct?}
  \item Yes
  \item No
\end{question}

\begin{question}{Is the numbering resuming?}
  \item Yes
  \item No
\end{question}

% RESUMES
\renewcommand{\labelitemi}{\large $\square$}
\begin{enumerate}[resume]
  \item Question 1
  \begin{itemize}
  \item Yes
  \item No
  \end{itemize}
\end{enumerate}
\begin{enumerate}[resume]
  \item Question 2
\end{enumerate}

\end{document}

First I tried just using enumerate within the newenvironment instead of defining the new list, but after reading this thread I figured I'd try defining the newlist and setting the resume option before the newenvironment, but that also did not work.

I was about to just post the above code and give up for awhile, but instead I tried defining my own counter to use within the newenvironment and got a resume-like ability. I'm not sure if it would solve the OP's problem (its over a year old anyways), but maybe it will help others trying to use resume in newenvironment.

Code: Select all

\documentclass{article}

\usepackage{enumitem} 
\usepackage{amssymb}

\newcounter{qstn}

\newenvironment{question}[1]
{\begin{itemize}
  \addtocounter{qstn}{1}
  \item[\bf\arabic{qstn}.] \textbf{#1}   % #1 variable is the survey question 
  \begin{itemize}\renewcommand{\labelitemii}{\large $\square$}}
  % all \item in the question environment will be the answer options.
{ \end{itemize} 
\end{itemize}}

\begin{document}

\begin{question}{Question environment correct?}
  \item Yes
  \item No
\end{question}

\begin{question}{Is the numbering resuming?}
  \item Yes
  \item No
\end{question}

\end{document}
Post Reply