3

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: enter image description here

The expected out is given below. enter image description here

2

Here is an automation:

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


\newcommand{\Answer}{\let\oldtheenumi=\theenumi\def\theenumi{\arabic{enumi}}\item[Answer \theenumi] \leavevmode\let\theenumi\oldtheenumi}

\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% this is automated now

\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.

| improve this answer | |
  • If you prefer, you can use \item[Answer \theenumi\space] – koleygr Oct 14 '17 at 17:24
4

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

enter image description here

\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
   \noindent Problem \theproblem\quad #1% Set problem heading
   \begin{enumerate}[label=(\alph*)]}
  {\end{enumerate}}
\newenvironment{answer}
  {\par
   \needspace{3\baselineskip}% Need at least 3 lines of text left on page
   \noindent Answer \theproblem% Set answer heading
   \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}

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

\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}

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

\end{document}
| improve this answer | |

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.