Text Formattingbegin{center} adds vertical space?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
tonyjnel
Posts: 11
Joined: Thu May 12, 2011 3:51 pm

begin{center} adds vertical space?

Post by tonyjnel »

Hi,

I am new to LaTeX and this community. This is my first post. I made a custom environment for Examples in my paper but when I center the example text it also adds vertical space between name of the example (Example 1) and the text below. I don't want it to do this and I am wondering if that is just a property of the command or if there is something weird going on caused by my environment or something.

Here is the code:

Code: Select all

\documentclass[12pt]{article}
\newcounter{example}\setcounter{example}{0}
\newenvironment{example}{\refstepcounter{example} \vspace{3mm} \noindent \textbf{Example \arabic{example}}\\ \indent}{\vspace{6mm}}
\begin{document}

\begin{example} \label{addexample}
\begin{center} Stuff \end{center}
\end{example}

\begin{example} \label{addexample}
Stuff 
\end{example}
\end{document}
\end{document}
I would expect the two examples to have the same vertical spacing but they don't. Do I have to manually subtract vertical space to make them look the same?

Thanks!
-Tony
Last edited by tonyjnel on Thu May 12, 2011 7:45 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

begin{center} adds vertical space?

Post by Stefan Kottwitz »

Hi Tony,

welcome to the board!

The center environment adds vertical space because it's implemented as a list environment. You can use \centering instead which doesn't add this space. See center vs. \centering for further information.

Stefan
LaTeX.org admin
tonyjnel
Posts: 11
Joined: Thu May 12, 2011 3:51 pm

Re: begin{center} adds vertical space?

Post by tonyjnel »

Thanks, Stefan, that did the trick :)

It also shifted the title of the example but I modified the environment by adding \flushleft before the title of the example to fix that.

-Tony
Post Reply