0

My objective is to put a tcolorbox around one or more AMS multline environment(s). However, there is extra space above the first equation. Presumably I'm running into an issue like this.

I have not found a solution that addresses this situation directly (most seem to address align in tcolorboxes such as this). One solution addresses it indirectly here and if I use -6pt I can get somewhat even vertical alignment. I couldn't find a good way to set this via variable (e.g., \baselineskip).

I have also experimented with empheq but could not get it to behave in the desired way.

My questions:

  1. Is there a better way to handle a tcolorbox around an AMS multline directly?
  2. If not, is there a better way to do what I've done either by either setting up a custom tcolorbox to always include the "displayskips" and/or not having to hard code the abovedisplayskip value?

A MWE is shown below; my real equation is quite complicated and requires a multline (I'd much rather not try to use an alternative environment because of the amount of equation number management I would need to do in my write up).

Edit to clarify:

I want to emphasize the equations I put inside the box relative to the progression leading up to them and those that follow. So, I want the tcolorbox to respect the typical intra- and inter-paragraph line spacing and not act as an equation but then within the tcolorbox to have even vertical alignment.


MWE:

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}

\begin{document}

An example \texttt{multline} formula is:

\begin{tcolorbox}
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}
\end{tcolorbox}

\end{document}

Problematic Layout


MWE with workaround:

...
\begin{tcolorbox}
  \abovedisplayskip=-6pt
  \belowdisplayskip=0pt
  \begin{multline}
...

Fixed Layout via Workaround

  • what about \begin{tcolorbox}\vspace{-\baselineskip}\begin{multline}...\end{tcolorbox}. Notice that I accidentally typed \begin{tcolorbox}\vspace{—\baselineskip}\begin{multline}... which gives amusing unexpected result. – user4686 Sep 15 '18 at 15:21
  • @jfbu, This causes the space at the top to be larger than below as I noted in my question. – Joel Kulesza Sep 15 '18 at 15:28
  • it is matter of taste, just compare with not using the tcolorbox at all and directly An example \texttt{multline} formula is: \begin{multline}.... The space above equation is very much the same (I did not measure) as when there is an extra \begin{tcolorbox}\vspace{-\baselineskip}...) – user4686 Sep 15 '18 at 15:32
  • @jfbu Yes, it's a matter of taste but also a matter of vertical alignment. I want a boxed multiline equation with even vertical alignment and spacing. To not achieve that doesn't achieve the objective regardless of taste. – Joel Kulesza Sep 15 '18 at 15:35
  • OK, but did you look at how it comes out without any tcolorbox? what you call "even vertical alignment and spacing" is not clear, else the amsmath creator would have not designed it this way. – user4686 Sep 15 '18 at 15:38
2

I was testing the \useshortskip command from nccmath, and noticed that simply loading the package seems to solve the problem:

\documentclass{article}

\usepackage{amsmath, nccmath}
\usepackage[most]{tcolorbox}

\begin{document}

An example \texttt{multline} formula is:

\begin{tcolorbox}
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}
\end{tcolorbox}

\end{document} 

enter image description here

| improve this answer | |
  • +1 indeed millimeter grid as in my answer seems to indicate this does it in the sense of achieving same vertical spacing as without tcolorbox. I do not know the details of tcolorbox, does it compensate its frame rule etc..., so it might also be quite a coincidence that this achieves same as in my answer (better than my answer), i.e. same vspacing as without presence of tcolorbox. – user4686 Sep 15 '18 at 16:27
  • @Bernard, Excellent, this worked quite well; however, before loading nccmath I had to \let\nr\relax\usepackage{nccmath} because it conflicted with another package's definition. I leave this comment future readers. – Joel Kulesza Sep 15 '18 at 16:49
  • Oh! Where is it defined other than nccmath (I never used the nccmath version anyway)? – Bernard Sep 15 '18 at 16:53
  • @Bernard, I'm not sure and I didn't search for it. This is for my dissertation that loads a lot of packages, so hunting down the error would take much longer than fixing it. – Joel Kulesza Sep 15 '18 at 17:14
  • @Bernard \nr is defined in loops and in ltxtools-base. – user4686 Sep 15 '18 at 17:21
2

You could use the key ams nodisplayskip:

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}

\begin{document}

An example \texttt{multline} formula is:
\begin{tcolorbox}[ams nodisplayskip]
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}
\end{tcolorbox}

An example \texttt{multline} formula is:
\begin{tcolorbox}
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}
\end{tcolorbox}

\end{document}

enter image description here

| improve this answer | |
  • It seems like this has the same effect as what @jfbu suggested, removing the baseline skip. Is there a reason why the space above the multline is slightly larger than below? – Joel Kulesza Sep 15 '18 at 15:51
0

In order to empirically determine the needed correction (expecting it to remain applicable of course for other multline things), I used the device of a millimeter grid. Roughly, one needs -6mm to recover the same vertical spacing as in absence of tcolorbox. I understand from OP this is still too much, then one only needs to increase the 6mm.

\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}

\def\mygraphpaper{% copied/adapted from https://tex.stackexchange.com/a/311407/4686
  \begin{tikzpicture}
    \draw[line width=.4pt,draw=black!20] (0,0) grid[step=1mm] (\paperwidth,\paperheight);
    \draw[line width=.4pt,draw=red!30] (0,0) grid[step=10mm] (\paperwidth,\paperheight);
  \end{tikzpicture}%
}
\usepackage{tikz}

\usepackage{eso-pic}% has a grid option but not easily customizable

\AddToShipoutPictureFG{\AtPageLowerLeft{\mygraphpaper}}
% advantage to https://tex.stackexchange.com/a/311407/4686 is that
% a single compilation is needed.

\usepackage{geometry}

\begin{document}

An example \texttt{multline} formula is:
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}

An example \texttt{multline} formula is:
\begin{tcolorbox}
\vspace{-6mm}
  \begin{multline}
    f(x) = 1 + 2 + 3 + 4\\
    + 5 + 6 + 7 + 8 + 9\\
    + 10.
  \end{multline}
\end{tcolorbox}

\end{document}

enter image description here

In both cases the distance between baseline above and bottom of x in f(x) appears to be a bit less than 9mm. One could also examine log output of \showoutput... to be more precise.

| improve this answer | |

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.