1

I am using the tcolorbox package for some boxes which often contain equations. If there is some text prior to the equation- or align-environment which is long enough to force the equation to be set down a bit, there is no problem in spacing. Both boxes have the same height (see first picture). There is no problem, when there is enough text prior to the align-environment.

But if there is not enough text above it, or no text at all, the equation-environment appears a bit further up, which is just right. But the align-environment does not behave like this, it has got too much space above it. That is why the two boxes differ in height (see second picture). While the equation-environment appears a bit further up, the align-environment does not behave like this, if there is not enough text prior to the environment.

This is my MWE, which creates the boxes shown in the pictures:

\documentclass[ngerman,a4paper,12pt]{scrbook}

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

\usepackage{amsmath,amssymb}

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\definecolor{maple-hblau}{RGB}{58,126,171}
\colorlet{colexample}{maple-hblau!75}
\newtcolorbox{examplebox}{%
empty,title={Example},attach boxed title to top left,
boxed title style={empty,size=minimal,toprule=2pt,top=4pt,overlay={\draw[colexample,line width=2pt] ([yshift=-1pt]frame.north west)--([yshift=-1pt]frame.north east);}},
coltitle=colexample,fonttitle=\footnotesize\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=4pt,
overlay={\draw[colexample,line width=1pt] ([yshift=-1pt]title.north east)--([xshift=-0.5pt,yshift=-1pt]title.north-|frame.east)--([xshift=-0.5pt]frame.south east)--(frame.south west); },
}

\begin{document}

\twocolumn

% long text prior to the align-environment -> no problem
\begin{examplebox}
  Align*-Environment:
  \begin{align*}
      \frac{5}{2} = \frac{15}{6}    
    \end{align*}
\end{examplebox}

\newpage

% long text prior to the equation-environment, for comparison
\begin{examplebox}
  Equation*-Environment:
  \begin{equation*}
    \frac{21}{9} = \frac{7}{3}
  \end{equation*}
\end{examplebox}

\newpage

% not enough text prior to the align-environment -> too much white space above align
\begin{examplebox}
  Align*:
  \begin{align*}
      \frac{5}{2} = \frac{15}{6}    
    \end{align*}
\end{examplebox}

\newpage

% the same amount of text prior to the equation-environment, for comparison
\begin{examplebox}
  Equation*:
  \begin{equation*}
    \frac{21}{9} = \frac{7}{3}
  \end{equation*}
\end{examplebox}

\end{document}

Is there a reason for the align-environment behaving like this or is this a bug?

And the more important question: How do I change this behavior of align, so that the box with the align-environment and just a bit text above it is as big as the box with the equation-environment besides it, so there is less space above the align-environment? Best would be to define this behavior globally, so I don't have to insert some command every time there is the align-environment and very little text above it.

  • 1
    LaTeX's single-line equation environments -- equation and equation* -- use either \abovedisplayskip or \abovedisplayshortskip, depending on the length of the line that immediately precedes the environment. In contrast, the multiline equation environments of the amsmath package use only \abovedispkayskip. – Mico Aug 14 '17 at 0:14
3

This is a known problem: align doesn't use the shortskips.

The solution is to load the nccmath package, and to use the \useshortskip command before align:

\documentclass[ngerman,a4paper,12pt]{scrbook}

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

\usepackage{amsmath,amssymb}
\usepackage{nccmath}

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\definecolor{maple-hblau}{RGB}{58,126,171}
\colorlet{colexample}{maple-hblau!75}
\newtcolorbox{examplebox}{%
empty,title={Example},attach boxed title to top left,
boxed title style={empty,size=minimal,toprule=2pt,top=4pt,overlay={\draw[colexample,line width=2pt] ([yshift=-1pt]frame.north west)--([yshift=-1pt]frame.north east);}},
coltitle=colexample,fonttitle=\footnotesize\bfseries,
before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=4pt,
overlay={\draw[colexample,line width=1pt] ([yshift=-1pt]title.north east)--([xshift=-0.5pt,yshift=-1pt]title.north-|frame.east)--([xshift=-0.5pt]frame.south east)--(frame.south west); },
}

\begin{document}

\twocolumn

% long text prior to the align-environment -> no problem
\begin{examplebox}
  Align*-Environment:%\useshortskip
  \begin{align*}
      \frac{5}{2} = \frac{15}{6}
    \end{align*}
\end{examplebox}

\newpage

% long text prior to the equation-environment, for comparison
\begin{examplebox}
  Equation*-Environment:
  \begin{equation*}
    \frac{21}{9} = \frac{7}{3}
  \end{equation*}
\end{examplebox}

\newpage

% not enough text prior to the align-environment -> too much white space above align
\begin{examplebox}
  Align*:\useshortskip
  \begin{align*}
      \frac{5}{2} = \frac{15}{6}
    \end{align*}
\end{examplebox}

\newpage

% the same amount of text prior to the equation-environment, for comparison
\begin{examplebox}
  Equation*:
  \begin{equation*}
    \frac{21}{9} = \frac{7}{3}
  \end{equation*}
\end{examplebox}

\end{document} 

enter image description here

  • 1
    The solution is not to load the nccmath package but rather to use equation instead of align for single-line formulas. I would argue that align does not use the short skips by design. – Henri Menke Aug 14 '17 at 0:15
  • You're right, but I suppose the O.P. meant he really needs to use a multilined equation. – Bernard Aug 14 '17 at 0:25
  • 1
    Then there should also be a large skip around the equation. – Henri Menke Aug 14 '17 at 0:54
  • 1
    "This is a known problem". I think this claim is too negative and too dismissive. The problem lies not in the amsmath package's multiline-math environments not using \abovedisplayshortskip and \belowdisplayshortskip. Instead, as Henri Menke has already pointed out, the real problem lies with those users who employ align and gather for single-line displayed equations despite the amsmath package providing numerous warnings not to do so. If anything, the authors of the amsmath package were guilty of having been too optimistic about users actually heeding such warnings. – Mico Aug 14 '17 at 5:22
  • 1
    the failure of amsmath to use \abovedisplayshortskip for multi-line display environments has been on the bugs list for a very long time. the cause is the necessity of multi-line displays to measure the width in order to accommodate equation numbers; no account has been taken for the *ed version. i'm sure a good answer has been given for this already, but i'm unable to find it. – barbara beeton Aug 14 '17 at 13:07

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.