16

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}
1
  • 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.
    – user11232
    Commented Sep 26, 2012 at 16:25

2 Answers 2

5

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.

8

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).

6
  • 1
    Just to make sure: is it that that \topsep influences both top and bottom margin, isn't it?
    – yo'
    Commented Sep 26, 2012 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
    Commented Sep 26, 2012 at 17:07
  • @tohecz Yes, it would be nice to control them separately but I can live with \topsep.
    – schremmer
    Commented Sep 26, 2012 at 17:24
  • 2
    @tohecz \topsep influences top separation, not bottom
    – cmhughes
    Commented Sep 26, 2012 at 18:22
  • 3
    How to remove the bottom space? It is not clear from your answer. Please let me know.
    – Rajat
    Commented Jun 9, 2017 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .