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.

Is it possible to control the space above and below center, e.g. the way it can be controlled above and below math display? In other words, is there an equivalent to, say,

\setlength\abovedisplayskip{3pt plus 2pt minus 2pt}
\setlength\belowdisplayskip{3pt plus 2pt minus 2pt}
share|improve this question
3  
Do you mean \begin{center}? Use \centering within a group. Say, \bgroup \centering ... your code ... \egroup'. You can use \begingroup` and \endgroup or simply enclose the code between {} to form a group. –  Harish Kumar Sep 26 '12 at 16:25
add comment

2 Answers

up vote 2 down vote accepted

You can define your mycenter environment and pass a length (optionally) to modify the top/bottom gap:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\newenvironment{mycenter}[1][\topsep]
  {\setlength{\topsep}{#1}\par\kern\topsep\centering}% \begin{mycenter}[<len>]
  {\par\kern\topsep}% \end{mycenter}
\setlength{\parindent}{0pt}% Just for this MWE
\begin{document}
1: \lipsum[2]
\begin{center}
  2: \lipsum[2]
\end{center}
3: \lipsum[2]
\begin{mycenter}
  4: \lipsum[2]
\end{mycenter}
5: \lipsum[2]
\begin{mycenter}[0pt]
  6: \lipsum[2]
\end{mycenter}
7: \lipsum[2]
\end{document}

geometry and lipsum were loaded specifically for this MWE, and may not be needed in your final document.

share|improve this answer
add comment

The center environment is actually defined in terms of a list, so you can tweak all the parameters detailed in Section 56 of source2e.

In terms of the spacing above the center environment, you can use something like

\documentclass{article}
\usepackage{lipsum}
\let\oldcenter\center
\let\oldendcenter\endcenter
\renewenvironment{center}{\setlength\topsep{0pt}\oldcenter}{\oldendcenter}
\begin{document}

\lipsum[1]
\begin{center}
    \lipsum[2]
\end{center}

\end{document}

The spacing below could be controlled by adding some glue at the end of the environment (after \oldendcenter).

share|improve this answer
    
Just to make sure: is it that that \topsep influences both top and bottom margin, isn't it? –  tohecz Sep 26 '12 at 16:52
    
I want to control the space above and below the center environment but only in certain instances and \setlength\topsep{0pt} controls space both above and below \begin{center} xxx \end{center} –  schremmer Sep 26 '12 at 17:07
    
@tohecz Yes, it would be nice to control them separately but I can live with \topsep. –  schremmer Sep 26 '12 at 17:24
1  
@tohecz \topsep influences top separation, not bottom –  cmhughes Sep 26 '12 at 18:22
    
@user15042 it wasn't obvious that you wanted to have only certain instances; I assumed you wanted to change all of them. Looks like Werner has given a way to do certain instances –  cmhughes Sep 26 '12 at 18:24
add comment

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.