1

Inspired by this answer (to define a center environment with no vertical spacing):

\newenvironment{nscenter}
 {\parskip=0pt\par\nopagebreak\centering}
 {\par\noindent\ignorespacesafterend}

I defined my center environment with custom vertical spacings:

\newenvironment{mycenter}
 {\par\addvspace{1.5ex}%
 \nopagebreak\centering}
 {\par\addvspace{1.5ex}%
 \ignorespacesafterend}

But now I do not know how to implement the \noindent part in the original answer. What am I supposed to do?

(I am aware that I can solve it using the noindentafter package, but I am trying to understand how things work.)

blackened
  • 4,181

1 Answers1

1

Is this what you want?

\documentclass{article}

\usepackage{lipsum}

\newenvironment{nscenter}
 {\setlength{\topsep}{1.5ex}\trivlist\item\relax\centering}
 {\endtrivlist}

\begin{document}

\lipsum*[2]
\begin{nscenter}
This is \\
centered
\end{nscenter}
and this is not indented. \lipsum*[3]
\begin{nscenter}
This is \\
centered
\end{nscenter}

And this is indented, because of the empty line.

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you. I always learn new things from your answers. Visually, yes, that is what I want. To understand better: Does your answer suggest that compared to mycenter macro above, your answer the the proper way? And does it suggest that what I am asking cannot be incorporated into mycenter macro? Further, is it possible to modify your macro such that the following paragraph is not indented when there is an empty line? (Because, perhaps, I never want indented paragraphs after a center environment.) – blackened Sep 21 '15 at 17:41
  • @blackened It's surely possible to have the behavior you'd like, but I can see no reason for it. – egreg Sep 21 '15 at 19:36