# Correct way to set indent to zero in newcommand

I define a new command to number the problems in a chapter:

\newcounter{problemNo} %problem counter
\setcounter{problemNo}{1} %start at one
\newcommand\problem[1]{\textbf{Problem \thechapter.
\arabic{problemNo} }#1 \par\smallskip\stepcounter{problemNo}\noindent}


This code has some indentation problems:

I also tried to use \setlength{\parindent}{0cm}, but with no luck:

\newcommand\problem[1]{\textbf{Problem \thechapter.\arabic{problemNo}
}#1 \par\smallskip\stepcounter{problemNo}\setlength{\parindent}{0cm}}


In fact, now the indent is zero everywhere.

What is the right way for removing the indentation only after the \problem command?

Complete code:

\documentclass[12pt,twoside]{book}

\newcounter{problemNo}
\setcounter{problemNo}{1}
\newcommand\problem[1]{\textbf{Problem \thechapter.
\arabic{problemNo} }#1 \par\smallskip\stepcounter{problemNo}\noindent}

\begin{document}

\chapter{Problems}

\problem{Solve this problem:}
Problem statement.\\

\problem{Solve this problem too:}
Problem statement.\\

\end{document}

• Why don't use \newtheorem{problem}{Problem}[chapter]? Load amsthm – Sigur Nov 2 '18 at 1:11

Here is an option:

\documentclass{book}

\newcounter{problemNo}[chapter]
\renewcommand{\theproblemNo}{\thechapter.\arabic{problemNo}}
\newcommand{\problem}[1]{%
\par
\refstepcounter{problemNo}%
\noindent\textbf{Problem \theproblemNo}
#1
\par\nobreak
\smallskip
\noindent\ignorespaces
}

\begin{document}

\chapter{Problems}

\problem{Solve this problem:}
Problem statement.

\problem{Solve this problem too:}
Problem statement.

\end{document}


What changed:

• Proper definition of problemNo counter to reset with every [chapter] and have a representation that includes the chapter number representation (\thechapter).

• A \problem starts by adding some space up to \bigskipamount.

• The problemNo counter is stepped just before setting Problem X.Y; this allows for proper referencing if you use \label-\ref.

• After setting the problem statement, a \paragraph break is initiated without a possibility for a page break (thanks to \nobreak). This avoids having Problem X.Y at the bottom of the page and the problem statement at the top of the following page.

Subsequent paragraphs of a problem statement will have a regular \parindent. If you want to avoid this altogether, add \setlength{\parindent}{0pt} to your preamble.

A completely different approach would be to define your \problem as an environment similar to that of a theorem. However, this would require a change in your input.

\documentclass[12pt,twoside]{book}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{problem}{Problem}[chapter]

\begin{document}

\chapter{Problems}

\begin{problem}
Solve this problem:\\ Problem statement.
\end{problem}

Text in middle.

\begin{problem}
Solve this problem:\\ Problem statement.
\end{problem}

\begin{problem}
Solve this problem:\\ Problem statement.
\end{problem}

\end{document}