I have defined an environment called exercise
as follows:
\newcounter{exercise}
\NewDocumentEnvironment{exercise}{o +b}%
{%
\IfNoValueTF{#1}
{\stepcounter{exercise}}
{\setcounter{exercise}{#1}}%
\par\noindent\makebox[2em][l]{\textbf{\theexercise.}}%
\hangindent = 3em \hangafter = 1 #2\par}%
{\ignorespacesafterend}
And I test it as follows:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{lipsum}
\newcounter{exercise}
\NewDocumentEnvironment{exercise}{o +b}%
{%
\addvspace{\topsep}%
\IfNoValueTF{#1}
{\stepcounter{exercise}}
{\setcounter{exercise}{#1}}%
\par\noindent\makebox[2em][l]{\textbf{\theexercise.}}%
\hangindent = 3em \hangafter = 1 #2\par}%
{\ignorespacesafterend}
\begin{document}
\begin{exercise}[8]
\lipsum[1][1-2]
\end{exercise}
\begin{exercise}
\lipsum[1][3-4]
\end{exercise}
\begin{exercise}[11]
\lipsum[1][5-6]
\begin{enumerate}[label = \textbf{\alph*.}]
\item \lipsum[2][1-2]
\item \lipsum[2][3-4]
\item \lipsum[2][5]
\end{enumerate}
\end{exercise}
\end{document}
Output:
The vertical red line is added by myself. My question is how to refine the code such that the enumerate part can automatically start from the right side of the line (i.e., to make it also have a corresponding indentation)?
\usepackage{showframe}