0

I already have found the solution to define a new environment without the additional space above the paragraph. But why does the "vanilla" way of defining this not work?

Pictures

enter image description here

MWE

\documentclass[
fontsize=11pt,
DIV=12,
paper=a4,
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}

%%% the GOOD definition
\newenvironment{goodgood}{\ignorespaces\par\centering\begin{minipage}{0.8\linewidth}\small\sffamily}{\end{minipage}\par\ignorespacesafterend}

%%% the PROBLEMATIC definition
\newenvironment{asdf}{\begin{center}\begin{minipage}{0.8\linewidth}\small\sffamily}{\end{minipage}\end{center}}

\begin{document}

ABC
\begin{asdf}
    bad vertical spacing
\end{asdf}

DEF
\begin{goodgood}
    GOOD VERTICAL SPACING
\end{goodgood}

AAA
\end{document}
  • 3
    AFAIK \begin{center}...\end{center} adds space. See tex.stackexchange.com/q/23650/35864. So if you don't want additional space (which together with a minipage could add up), \begin{center}...\end{center} is probably not your weapon of choice. – moewe Dec 22 '18 at 20:21
  • 2
    As for the error: In the MWE \singlespacing is undefined. LaTeX throws an error (which should not be ignored!), but continues pretending \singlespacing wasn't there. – moewe Dec 22 '18 at 20:24
  • 1
    I'm not sure if you need the \ignorespaces at the beginning of the environment definition. It seems somewhat pointless to suppress spaces there, since they would have to come from the macro definition itself and there aren't any. I'm also not sure if the \ignorespacesafterend is needed here. – moewe Dec 22 '18 at 20:36
  • 3
    It's a bit later for me now, but I will write up an answer tomorrow if no one complains about what I commented here. – moewe Dec 22 '18 at 20:56
  • 2
    also \ignorespaces\par is the same as \par as there are no spaces between \ignorespaces and \par. – David Carlisle Dec 22 '18 at 21:02
1

As explained in When should we use \begin{center} instead of \centering? \begin{center}...\end{center} is implemented via a list (\trivlist) and causes vertical space before and after the centred text. \centering on the other hand will not add additional vertical space.

That means that your asdf environment gets the 'usual' vertical spacing of a display environment, while goodgood just gets the spacing one gets when moving on to the next paragraph (due to the \par).

You don't need the \ignorespaces at the beginning of goodgood: \ignorespaces\par is the same as \par as David Carlisle pointed out in the comments. Since the environment ends with a \par I also don't think the \ignorespacesafterend is required.

  • To add some evenly divided space above and below, is it good practice to simply add \vspace{2.0ex} at the beginning and end? Like this: -> \newenvironment{specialnote}{\vspace{2ex}\par\centering\begin{minipage}{0.8\linewidth}\small\sffamily}{\end{minipage}\par\vspace{2ex}} (You switched asdf and goodgood, btw.) – henry Dec 31 '18 at 16:18
  • @henry Thanks for catching the name confusion (I hope the edit fixed it). I'm not sure about best practices with \vspace. I'd have thought it would be more natural to use \trivlist or a \list, but I'm not sure what one would have to do to get what you wanted then. Maybe you should ask a new question about that. – moewe Dec 31 '18 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.