15

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} {\medskip \end{shaded}} 

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)?

3 Answers 3

11

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.

3
  • Looks like something that should work but I can't get it to work... :( Commented Oct 12, 2010 at 12:10
  • I am beginning to think that <code>\ignorespaces</code> only ignores spaces and not newlines. At least that is my feeling for the moment... Commented Oct 12, 2010 at 12:40
  • Ah. You want to trim newlines too. Answer modified to reflect that. Commented Oct 12, 2010 at 13:17
5

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.)

1
  • Ah yea that's it. Commented Oct 14, 2010 at 8:31
4

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

https://texfaq.org/FAQ-atvert

3
  • Hm yea now it accepts the command. However it still indents... :( Commented Oct 12, 2010 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. Commented Oct 13, 2010 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! Commented Oct 14, 2010 at 8:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.