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.

If I use the url package and include a url on a line inside the centering environment, it shows up left-justified instead of centered. How can I make it centered?

MWE:

\documentclass{article}
\usepackage{url}
\pagestyle{empty} % no page numbers 

\begin{document}
\begin{centering}
\par My Name
\par My Department
\par My Department But With More Words
\par My department's Address
\par My phone number and e-mail address
\par Website: \url{http://my.web.site/}
\end{centering}

\end{document}
share|improve this question

2 Answers 2

up vote 4 down vote accepted

The setting of a paragraph is done when encountering a \par (or empty line). Adding \par to the last line provides the appropriate horizontal alignment:

enter image description here

\documentclass{article}
\usepackage{url}% http://ctan.org/pkg/url
\pagestyle{empty} % no page numbers 

\begin{document}
\begin{centering}
My Name \par
My Department \par
My Department But With More Words \par
My department's Address \par
My phone number and e-mail address \par
Website: \url{http://my.web.site/}\par
\end{centering}

\end{document}​

As such, your initial \par has no effect. Of course, there are other ways of obtaining this output as well:

\begin{center}
  My Name \\
  My Department \\
  My Department But With More Words \\
  My department's Address \\
  My phone number and e-mail address \\
  Website: \url{http://my.web.site/}
\end{center}
share|improve this answer

\centering is not designed to be used as an environment. As @Werner noted it does not center the last paragraph if used without an explicit paragraph end. Use center instead of centering. The problem is unrelated to \url you would see the same effect with plain text.

share|improve this answer

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.