1

I like to enclose two subfigures, which I use to display align environments side by side in a framebox. However, this leads to ugly padding at the top of the box.

enter image description here

A earlier post (Where does the space before \align* come from?) emphasizes, that it is never a good idea to have a par before a math environment.

I am curious whether this is the problem here and how to avoid it.

Please note, that I need the align environment indeed and that the problem seems not to depend of its content.

\documentclass[fontsize=11pt,paper=a4,headsepline,footsepline,DIV=13,BCOR=12mm,bibliography=toc,chapterprefix=on]{scrbook}

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

% serveral packages

\usepackage{lmodern}
\usepackage[final]{microtype}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{lipsum} %%% can be delted in the end !!!!!!

% figures and captions

\usepackage{caption}
\captionsetup{format=plain, width=.9\textwidth}
\usepackage{subcaption}

\begin{document}

\lipsum[1]

\lipsum[2]

\begin{figure}[h]%
    \framebox[\textwidth]{\begin{subfigure}[t]{.5\textwidth}
            \begin{align*}%
                E = m \cdot c^2
            \end{align*}
        \end{subfigure}%
        \begin{subfigure}[t]{.5\textwidth}%
            \begin{align*}%
                E = m \cdot c^2
            \end{align*}
    \end{subfigure}}
    \caption{Some caption.}
\end{figure}

\lipsum[1]

\lipsum[3]

\end{document}

1
  • Might you make a better example that shows the need for subfigure?
    – egreg
    Commented Nov 10, 2021 at 20:59

4 Answers 4

1

By use of the empheq package and flalign environment:

\documentclass{article}
\usepackage{empheq}
\usepackage{xcolor}
\setlength\fboxsep{6pt}

\usepackage{lipsum}

    \begin{document}
\lipsum[1]
    \begin{empheq}[box=\fcolorbox{red}{white}]{flalign*}
&&  
    F & = ma    
& 
  E &= mc^2   
&&
    \end{empheq}
\lipsum[2]
    \end{document}

enter image description here

0

You can set the spacing above and below the align environments to zero (see this answer). If you do this inside the figure environment, these settings are only applied within this environment.

It may be true that it is not a good idea to place a math environment directly after a \par, but since you wrap the align environment inside a figure, I think that this should not be a problem here.

\documentclass[fontsize=11pt, paper=a4, headsepline, footsepline, DIV=13, BCOR=12mm, bibliography=toc, chapterprefix=on]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[ngerman,american]{babel}
\usepackage[utf8]{inputenc}

% serveral packages

\usepackage{lmodern}
\usepackage[final]{microtype}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{lipsum} %%% can be delted in the end !!!!!!

% figures and captions

\usepackage{caption}
\captionsetup{format=plain, width=.9\textwidth}
\usepackage{subcaption}

\begin{document}

\lipsum[1]

\lipsum[2]

\begin{figure}[h]%
    \setlength{\abovedisplayskip}{0pt}%
    \setlength{\belowdisplayskip}{0pt}%
    \setlength{\abovedisplayshortskip}{0pt}%
    \setlength{\belowdisplayshortskip}{0pt}%
    \framebox[\textwidth]{%
        \begin{subfigure}[t]{.5\textwidth}%
            \begin{align*}%
                E = m \cdot c^2
            \end{align*}%
        \end{subfigure}%
        \begin{subfigure}[t]{.5\textwidth}%
            \begin{align*}%
                E = m \cdot c^2
            \end{align*}%
        \end{subfigure}%
    }
    \caption{Some caption.}
\end{figure}

\lipsum[1]
%
\begin{align*}%
    E = m \cdot c
\end{align*}
%
\lipsum[3]

\end{document}

enter image description here

0

I see no reason for subfigure, unless you want to have subcaptions. Nor I see reasons for align* when a single equation is involved.

Anyway, use $\begin{aligned}...\end{aligned}$ for multiline displays or $\displaystyle...$ for a single equation.

\documentclass[fontsize=11pt,paper=a4,headsepline,footsepline,DIV=13,BCOR=12mm,bibliography=toc,chapterprefix=on]{scrbook}

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

% serveral packages

\usepackage{lmodern}
\usepackage[final]{microtype}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{lipsum} %%% can be delted in the end !!!!!!

% figures and captions

\usepackage{caption}
\captionsetup{format=plain, width=.9\textwidth}
\usepackage{subcaption}

\begin{document}

\lipsum[1]

\lipsum[2]

\begin{figure}[htp]

\framebox[\textwidth]{%
  \begin{subfigure}[t]{.5\textwidth}
  \centering
    $\begin{aligned}
      E &= m \cdot c^2 \\
      F &= ma
    \end{aligned}$
  \caption{Subfigure}
  \end{subfigure}%
  \begin{subfigure}[t]{.5\textwidth}
  \centering
    $\begin{aligned}
      E &= m \cdot c^2 \\
      F &= ma
    \end{aligned}$
  \caption{Subfigure}
  \end{subfigure}%
}% end of \framebox

\caption{Some caption.}
\end{figure}

\lipsum[1]

\end{document}

enter image description here

0

Basic Solution

\usepackage{adjustbox}

Manual: https://ctan.org/pkg/adjustbox

See, (Sec 4.2) margin=<left> <bottom> <right> <top>

In use:

\begin{figure} % ...
% ...
\begin{adjustbox}{margin=0em 0em 0em -1em, varwidth=\textwidth,fbox,center}
% ...
% subfigures, etc.. go here
% ...
\end{adjustbox}
% ...
\end{figure}

Effect: Shift the box up 1em.

Details

Overlooking the rationale for embedding subfigures, it looks like there are a few methods to solve this. I used adjustbox to solve it.

Requires a package adjustbox

https://ctan.org/pkg/adjustbox

I just set the top margin to -1em

MWE

\documentclass[12pt]{scrbook}
\usepackage{amsmath}
\usepackage{adjustbox}
\usepackage{subcaption}

\begin{document}

\begin{figure}[h]%
  \begin{adjustbox}{margin=0em 0em 0em -1em, 
                    varwidth=\textwidth,fbox,center}
        \begin{subfigure}[t]{.5\textwidth}
            \begin{align*}%
                E &= mc^2
            \end{align*}
        \end{subfigure}%
        \begin{subfigure}[t]{.5\textwidth}
            \begin{align*}%
                E &= mc^2
            \end{align*}
        \end{subfigure}
   \end{adjustbox}
\caption{Energy is matter is energy.}
\end{figure}

\end{document}

Result

enter image description here

You must log in to answer this question.

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