Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The combination of \addvspace{x}\addvspace{x} will cause the skip x but \addvspace{x}\noindent \addvspace{x} gives a 2x skip.

\documentclass{scrartcl}

\newenvironment{env}{%
    \par\addvspace{2\baselineskip}%
    \hspace*{2em}%
    \begin{minipage}{0.5\textwidth}%
}{%
    \end{minipage}%
    \par\addvspace{2\baselineskip}%
    \noindent\ignorespacesafterend%
}

\begin{document}
Line of text Line of text Line of text Line of text and
\begin{env}
--- \verb+env+ ---
\end{env}
no indent here. Line of text Line of text Line of text.

Next par (with indent). Line of text Line of text Line of text.
\begin{env}
--- \verb+env+ ---
\end{env}

Next par (with indent). Line of text Line of text Line of text.

\begin{env}
--- Two \verb+env+s following ---
\end{env}
\begin{env}
--- dont work with \verb+\addvspace+ ---
\end{env}
\end{document}

This example gives the doubled space. If i comment out the line \noindent\ignorespacesafterend% in the definition of {env} there is a single space with is the desired result but then the line no indent here ... will be indented which is not correct, I think.

Is it possible to make {env} behave like e.g. {equation}?

share|improve this question
1  
You should look at tex.stackexchange.com/questions/24495/… –  egreg Jan 7 '12 at 14:22
4  
With \noindent you're starting a paragraph; so the two \addvspace are not near to each other any more. –  egreg Jan 7 '12 at 14:33
    
This is one for xgalley! –  Joseph Wright Jan 7 '12 at 14:45
    
@JosephWright: I’m not shure if I understand your comment could you please explain it a little or add it as an answer? (I had a look hat xgalley.pdf but didn’t found something useful …) –  Tobi Jan 7 '12 at 16:20
    
@Tobi It was a slightly flippant remark. The idea in xgalley is to address these issues in a very different way at a low level. So for example \noindent is not 'start a paragraph with no indent' but 'set a flag such that the next paragraph which starts will have no indent'. This allows additive treatment of vspace, but is currently experimental. In any case, unlike other LaTeX3 code you can't just load xgalley and expect everything to continue working as before. –  Joseph Wright Jan 7 '12 at 16:22

1 Answer 1

up vote 8 down vote accepted

The \noindentstarts a paragraph and if that is immediately followed by an empty line it will be and empty paragraph but still prevent \addvspace to look backwards and see the previous \addvspace. So this is not the right approach to get the paragraph indentation suppressed.

What you should do instead is a variation of \@endparenv namely to set a boolean switch that signals special processing inside \end{...}. I.e.,

\makeatletter
\newenvironment{env}{%
    \par\addvspace{2\baselineskip}%
    \hspace*{2em}%
    \begin{minipage}{0.5\textwidth}%
}{%
    \end{minipage}%
    \par\addvspace{2\baselineskip}%
    \@endpetrue                       % <-- this is needed
}
\makeatother

As mentioned in a comment the processing that happens to make this "end-magic" work is nicely explained here.

share|improve this answer
    
Thanks, that works! :-) –  Tobi Jan 7 '12 at 16:12
    
You may be interested in tex.stackexchange.com/questions/39867/… –  lockstep Jan 7 '12 at 16:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.