How to alternatively display different names for even and odd entries in enumerate

I am making a list of problems, where answers are given below the problems. Currendesrired is the Answers should come with the same indentation as the Problems with Automatic numbers (same as the problem number.) For example, Problem 1 should be followed by Answer 1 and so on.

MWE is and its output is given below.

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}

\begin{document}
\begin{enumerate}[label={Problem \arabic*},leftmargin=2cm]
\item Find the least term of each sequence:

\begin{enumerate}[label=(\alph*)]
\item $y_{n} = n^{2} -5n + 1$
\item $y_{n} = n + \dfrac{100}{n}$
\item $y_{n} = n + 5 \sin\dfrac{\pi n}{2}$
\end{enumerate}
Answer 1 % this is manual now, should be auto with indent as \item
\begin{enumerate}[label=(\alph*)]
\item $y_{2} = y_{3}= -5$
\item $y_{10} = 20$
\item $y_{3} = -2$
\end{enumerate}

\item Find the largest term of each sequence:

\begin{enumerate}[label=(\alph*)]
\item $y_{n} = \dfrac{90n}{n^{2} + 9}$
\item $y_{n} = \dfrac{10^{n}}{n!}$
\end{enumerate}

Answer 2 % this is manual now, should be auto with indent as \item
\begin{enumerate}[label=(\alph*)]
\item $y_{3}= 15$
\item $y_{9} = y_{10} = \dfrac{10^{9}}{9!}$
\end{enumerate}

\end{enumerate}
\end{document}


This generates the following output:

The expected out is given below.

Here is an automation:

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}

\begin{document}
\begin{enumerate}[label={Problem \arabic*},leftmargin=2cm]
\item Find the least term of each sequence:

\begin{enumerate}[label=(\alph*)]
\item $y_{n} = n^{2} -5n + 1$
\item $y_{n} = n + \dfrac{100}{n}$
\item $y_{n} = n + 5 \sin\dfrac{\pi n}{2}$
\end{enumerate}

\begin{enumerate}[label=(\alph*)]
\item $y_{2} = y_{3}= -5$
\item $y_{10} = 20$
\item $y_{3} = -2$
\end{enumerate}

\item Find the largest term of each sequence:

\begin{enumerate}[label=(\alph*)]
\item $y_{n} = \dfrac{90n}{n^{2} + 9}$
\item $y_{n} = \dfrac{10^{n}}{n!}$
\end{enumerate}

\Answer % this is automated now
\begin{enumerate}[label=(\alph*)]
\item $y_{3}= 15$
\item $y_{9} = y_{10} = \dfrac{10^{9}}{9!}$
\end{enumerate}

\end{enumerate}
\end{document}


The result is exactly as your required image.

• If you prefer, you can use \item[Answer \theenumi\space] Oct 14 '17 at 17:24

I'd suggest changing your syntax to make the code more clear. Define a problem and answer environment:

\documentclass{article}

\usepackage{amsmath,enumitem,needspace}

\newcounter{problem}
\newenvironment{problem}[1]
{\par
\needspace{3\baselineskip}% Need at least 3 lines of text left on page
\refstepcounter{problem}% Mark counter increment
\begin{enumerate}[label=(\alph*)]}
{\end{enumerate}}
{\par
\needspace{3\baselineskip}% Need at least 3 lines of text left on page
\begin{enumerate}[label=(\alph*)]}
{\end{enumerate}}

\begin{document}

\begin{problem}
{Find the least term of each sequence:}
\item $y_{n} = n^2 - 5n + 1$
\item $y_{n} = n + \dfrac{ 100 }{ n }$
\item $y_{n} = n + 5 \sin \dfrac{ \pi n }{ 2 }$
\end{problem}

\item $y_2 = y_3 = -5$
\item $y_{10} = 20$
\item $y_3 = -2$

\begin{problem}
{Find the largest term of each sequence:}
\item $y_n = \dfrac{ 90n }{ n^2 + 9 }$
\item $y_n = \dfrac{ 10^n }{ n! }$
\end{problem}

\item $y_3 = 15$
\item $y_9 = y_{10} = \dfrac{ 10^9 }{ 9! }$