# center and \centering both add space above; \centerline does not

The nag package suggests I use the center environment in LaTeX, rather than the TeX \centerline command.

When I do that, however, I find that the former inserts a blank line above the line (in my case), whereas the latter does not.

I'd prefer to use the "correct" LaTeX env, but I don't want the extra blank line.

I tried \centering, as recommended here, but that still added space above, although that link suggests that it should not.

I'm doing this within the letter class, if that makes a difference.

-
center doesn't really add a blank line (LaTeX almost never does that) but it does add vertical space. \cemtering doesn't although if you paragrphs have space (\parskip) between them (as is default in letter) you may be seeing that. \left-\right and \centerline are odd constructs in latex, they are almost the only box commands that don't start a paragraph if in vmode, they are not color safe ad generaly they are a relic of theings being copied from plain TeX into LaTeX 1. – David Carlisle Feb 19 '13 at 2:02
If the content is just one line or in a box, then try doing something like \hspace*{\fill}<your content>\hspace*{\fill} – A.Ellett Feb 19 '13 at 2:05

You don't really want \centerline, that doesn't allow line breaks and whose behavior may surprise.

I don't really see why you want something centered inside a chunk of justified text without giving it some room. But if you really insist, \centering is the correct solution. It doesn't add more vertical space than what a normal start of paragraph would. If you're using a nonzero parskip, then you're the cause of your own trouble.

Here's a way to get a center environment that doesn't add vertical space around it even with nonzero parskip set.

\documentclass{article}
% \usepackage{parskip}

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

\begin{document}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
\begin{nscenter}
\bfseries Here's some short material\\ I wanted centered
\end{nscenter}
Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
\end{document}


Here's the result (thanks to A. Ellett for the precious text), first with zero parskip

and then with nonzero parskip (obtained by uncommenting the line in the source)

-
thanks; well I don't use a non-zero parskip, but it appears that the letter class does... – cdmackay Feb 19 '13 at 18:51
as to why I want this, I use it for the Subject of a letter, after the opening. The extra space added seems too much, to me. – cdmackay Feb 19 '13 at 18:54
@cdmackay I didn't notice the reference to letter, sorry. – egreg Feb 19 '13 at 18:54
np. Also, it's amusing that your "Don't use a nonzero parskip, your readers will be grateful." itself appears in a set of para, on this page here, that are separated by space :) – cdmackay Feb 19 '13 at 18:56
@cdmackay Nonzero parskip has its usages; here I have no control about it, because that's decided by the Powers That Be, but it's not so displeasing and perhaps good for the purpose of these messages. For longer documents it's distracting and spoils the page with white stripes. – egreg Feb 19 '13 at 18:58

You can use

\hspace*{\fill}This is my content\hspace*{\fill}


if all it is is one line to be centered.

Or, since the center environment is defined in terms of the \trivlist, you can use the definition of \trivlist to undo the unwanted extra whitespace.

\documentclass{article}
\pagestyle{empty}
\begin{document}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
purus elit, vestibulum ut, placerat ac, adipiscing vitae,     felis.
%%
\newline\hspace*{\fill}
\textbf{Here's some short material I wanted centered}
\hspace*{\fill}\newline
%%
Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et

\noindent\textbf{Here's a slew of stuff to center without added whitespace:}
\vspace{\dimexpr-2\parsep-2\parskip\relax}%
\begin{center}
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel,
wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at,
lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed
accumsan bibendum, erat ligula aliquet magna,
\end{center}
\vspace{\dimexpr-2\parsep-2\parskip\relax}%
%%
\textbf{Back to regular formatting:}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris.
\end{document}


-
very handy, thanks... – cdmackay Feb 19 '13 at 19:08