# No indentation at the beginning of environment

I am using the common approach of having indentations for new paragraphs and no indentation directly after a headline. I have an environment for 'information boxes' defined like this:

\newenvironment{sectionbox}[2][]{\begin{shaded}\refstepcounter{sectionbox}\par\medski\noindent%
\textbf{Box~\thesectionbox #1: #2
\vspace{0.1cm} \hrule \vspace{0.1cm}}\rmfamily}


The problem is that I don't want indentation at the beginning of these boxes -- they have a headline and hence they shouldn't have an indentation...

I have tried with \noindent but that isn't the right way since it only works when placed directly before the text which is to not be indented and the user of the environment might start with an empty line...

Google brought me to this page but their suggestion "\@afterindentfalse" is apparantly not something I can use since I am in the wrong mode as LaTeX pointed out to me: You can't use \spacefactor' in internal vertical mode.

So, what can I use (that fixes this)?

-

How'bout using \noindent\ignorespaces? See http://en.wikibooks.org/wiki/LaTeX/Customizing_LaTeX#Extra_space

If you use the following

\newenvironment{myEnv}%
{\noindent\ignorespaces\endlinechar=-1}%
{\endlinechar=13}


it will solve the problem of the first line being indented. But all endline characters in your environment will be gobbled, so you can't have paragraphs the usual way inside the environment.

Another option would be to use a trivial list (stolen from amsthm's proof environment)

\newenvironment{myEnv}%
{\noindent\trivlist\item\ignorespaces}%
{\endtrivlist}


which should, I think, do what you want, provided it plays well with the shaded environment. Whether either of this is suitable depends on your needs, of course.

-
 Looks like something that should work but I can't get it to work... :( – jonalv Oct 12 '10 at 12:10 I am beginning to think that \ignorespaces only ignores spaces and not newlines. At least that is my feeling for the moment... – jonalv Oct 12 '10 at 12:40 Ah. You want to trim newlines too. Answer modified to reflect that. – Willie Wong Oct 12 '10 at 13:17

Didn't the stackoverflow answer you referred to suggset using \@afterindentfalse \@afterheading ? Using just the former won't work. \@afterheading uses the \everypar token register to remove indentation at the first paragraph, when \@if@afterindent is false.

(I would have made this a comment to your comment to Ulrike's answer, but I haven't got the rep to comment yet.)

-
 Ah yea that's it. – jonalv Oct 14 '10 at 8:31

\@afterindentfalse contains a @, so you should make @ a letter before your definition. \makeatletter\newenvironment ...`

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=atvert

-
 Hm yea now it accepts the command. However it still indents... :( – jonalv Oct 12 '10 at 12:41 Well after I completed your example by loading the necessary class and packages, defining the counter and the color, correcting the typos in your code snippet and writing a small document body (which means that you would get much better answers if you would show complete minimal examples directly) I could suppress the indent without problem with ... \rmfamily\@afterindentfalse\@afterheading. – Ulrike Fischer Oct 13 '10 at 7:32 Oh so the trick was that \@afterindentfalse only works if followed by \@afterheading. This actually works even better because the trivlist created some extra vertical space. However I have started to like that space so I think I will keep that solution. Anyway thanks for teaching me how to make that command work! – jonalv Oct 14 '10 at 8:30