How to center text without adding space AND not altering alignment of surrounding text?
How about this:
\documentclass{article}
\begin{document}
This is a really long sentence as an example. The second have of this\\
\centerline{sentence should be centered.}
\end{document}
Please do not use \centerline
if possible, it's not suitable for long text. Just patch LaTeX's center
environment like this:
\documentclass{article}
\newenvironment{tightcenter}{%
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}
}{%
\end{center}
}
\begin{document}
text text text text text text text text text text text text text text text text text text text text text text text text
\begin{tightcenter}
foo
\end{tightcenter}
text text text text text text text text text text text text text text text text text text text text text text text text
\end{document}
You could use the TeX primitives \rightskip
and \leftskip
; a little example:
\documentclass{article}
\begin{document}
\begingroup
\leftskip=0cm plus 0.5fil \rightskip=0cm plus -0.5fil
\parfillskip=0cm plus 1fil
This is a really long sentence as an example. The last line of this
paragraph will be centered.\par
\endgroup
Another sentence that starts a new paragraph
\end{document}
The explanation of the code (as given in TeX by Topic):
For all lines of a paragraph but the last one the stretch components add up to zero so the
\leftskip
and\rightskip
inserted are zero. On the last line the\parfillskip
addsplus 1fil
of stretch; therefore there is a total ofplus 0.5fil
of stretch at both the left and right end of the line.