I am having an issue with a custom environment where the first line of the environment gets a space preceding it. The example below illustrates the behevior. It seems to happen because of the newline character after \begin{oppg}
. It also seems to have something to do with the \noindent
in line 7, since removing it fixes the issue (but I don't want the line to be indented).
As you can see, the issue is easily fixed by adding a %
at the end of the line when i begin the environment, but it seems to me that there should be a more robust way of doing it. There is probably an obvious explanation for this, but I can't see it.
\documentclass{article}
\newcounter{oppg}
\newenvironment{oppg}{%
\refstepcounter{oppg}%
\par\noindent\textbf{Oppgave \theoppg}%
\par\smallskip\noindent%
}%
{\bigbreak}%
\begin{document}
\begin{oppg}
Lorem ipsum, et cetera...
\end{oppg}
\begin{oppg}%
Lorem ipsum, et cetera...
\end{oppg}
\end{document}
\noindent
aftertabu
custom-environment\noindent
in latex (more or less ever) no standard latex command uses it except one use in\@hangfrom
\noindent
bad, and what is a good alternative?\noindent
always produces the issue that you ask about here. If you use\ignorespaces
as in the accepted answer here it masks some of the problems, but only some of them (for example you still can't leave a blank line) and it's better not to use it (and use a latex section or list item command) look at the definition of for example theorem environments which use exactly the kind of headed paragraph that you need here, they do not use\noindent