0

I am having trouble figuring out how to indent text in a custom environment

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

Currently, the text description of each problem does not indent. What I wish to achieve is for every new line of text to "align" with the red dashed line shown in this picture.

Is there a clean way to modify the code in order to achieve this? enter image description here

To illustrate another example, I wish to make the Problem environment have an indentation feature similar to the subsection environment: enter image description here

1
  • it would be helpful to upload a MWE which compiles
    – js bibra
    Jul 21, 2020 at 9:07

2 Answers 2

1

You can use the standard list environment.

\documentclass{article}
\usepackage{lipsum}

\newlength{\problemmargin}
\newenvironment{problem}[2][Problem]
 {%
  \settowidth{\problemmargin}{\hspace{\labelsep}\bfseries #1 #2.}%
  \begin{list}{}{\leftmargin=\problemmargin \labelwidth=\leftmargin}
  \item[\bfseries #1 #2.]%
 }
 {\end{list}}

\begin{document}

\lipsum[3]

\begin{problem}{21}
\lipsum[1][1-4]
\end{problem}

\lipsum[4]

\begin{problem}{22}
Solve the following equations
\begin{enumerate}
\item A
\item B
\item C
\end{enumerate}
and check the values.
\end{problem}

\lipsum[4]

\end{document}

enter image description here

1

Here is a solution, based on the description environment, using the tools of`enumitem. As you can see, it breaks across pages:

\documentclass{book}
\usepackage{enumitem}
\setlength\parindent{1em}
\newlength{\descrwidth}
\newenvironment{problem}[2][Problem]%
{\settowidth{\descrwidth}{\textbf{#1 #2}\hspace*{2\labelsep}}\begin{description}[font=\bfseries, labelindent=\labelsep, leftmargin =\descrwidth]
\item[#1\hspace*{ \labelsep}#2.]}%
{\end{description}}%

\usepackage{lipsum}
\pagestyle{plain}

\begin{document}

\lipsum[2-6]

\begin{problem}{21}%[noitemsep, labelwidth=\dimexpr\descrwidth, leftmargin =\descrwidth, labelsep=0pt]
\lipsum[11]
\end{problem} 

\lipsum[9]

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .