mdframed on several pages: bottom and top margins

by Ivan   Last Updated May 22, 2020 22:23 PM - source

Despite using splitbottomskip and splittopskip, I cannot manage to have:

  • the frame on page 1 to go to the end of \textheight,
  • the text inside the frame on page 2 to start after a small vertical space.

I had a look at this post but it's suggesting to use splittopmargin which I'm already using (and seems to have no effect).

Then I'm back in the \vspace nightmare I would like to avoid.

I post everything so you have the whole thing. It's several files I gathered into one xelatex-compilable. I'm also willing to hear any comment you may have on other parts of the code as all this is quite new to me.

\documentclass[a4paper,11pt]{article}

%%%%%%%%%
% Init  %
%%%%%%%%%

\usepackage[hmargin=2cm,bmargin=3cm,tmargin=4.5cm,centering]{geometry}

\usepackage{fontspec}
\setmainfont{Latin Modern Sans}

% Localization
\usepackage{polyglossia}
\setdefaultlanguage{french}

\usepackage[colorlinks=true,urlcolor=red]{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%
%  Graphics and colors  %
%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tikzpagenodes}

% Custom colors
\definecolor{BlackPen}{RGB}{40, 40, 40}
\definecolor{OrangePen}{RGB}{230, 150, 10}
\definecolor{LightGreen}{RGB}{25,170,75}

%%%%%%%%%
% Maths %
%%%%%%%%%

\usepackage{mathtools}
\usepackage[amsmath,thmmarks,hyperref]{ntheorem}
\usepackage[math-style=french]{unicode-math}

\setmathfont{XITS Math}
\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}

%%%%%%%%%%
%  Misc  %
%%%%%%%%%%

\usepackage[shortlabels]{enumitem}

\usepackage{multicol}

% Line spacing
\usepackage{setspace}
\onehalfspacing

% No indent for new paragraphs
\setlength\parindent{0pt}


%%%%%%%%%%%%%%%%%%%%%
%  Custom commands  %
%%%%%%%%%%%%%%%%%%%%%

\usepackage{lastpage}
\def\BaseColor{LimeGreen}

% Header
\newcommand\Header{
    \begin{tikzpicture}[remember picture,overlay]
    \fill[\BaseColor]
    (current page.north west) -- ([xshift=5cm]current page.north) -- ([xshift=3cm,yshift=75pt]current page.north|-current page text area.north) -- ([yshift=75pt]current page.north west|-current page text area.north west) -- cycle ;
    \node[font=\sffamily\bfseries\color{white},anchor=north west, xshift=55pt,yshift=-15pt] at (current page.north west) {\Huge Calcul littéral} ;
    \node[font=\sffamily\bfseries\color{BlackPen},anchor=north east,xshift=-1.5cm,yshift=-17pt] at (current page.north east) {\huge Correction} ;
    \node[font=\bfseries\color{\BaseColor},anchor=north west, xshift=55pt,yshift=-55pt] at (current page.north west) {\large 22 mai 2020} ;
    \end{tikzpicture}
}

% Footer
\newcommand\Footer{%
    \begin{tikzpicture}[remember picture,overlay]
    \fill[\BaseColor]
    (current page.south east) --
    ([yshift=-30pt]current page.south east|-current page text area.south east) --
    ([yshift=-30pt,xshift=7cm]current page.south|-current page text area.south) --
    ([xshift=5cm]current page.south) --
    cycle ;
    \node[xshift=-2cm,yshift=.9cm,font=\bfseries\color{white}] at (current page.south east) {\large Page \thepage\ sur \pageref*{LastPage}};
    \end{tikzpicture}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%
%  Custom environments  %
%%%%%%%%%%%%%%%%%%%%%%%%%

\theoremstyle{break}
\theorempreskip{1cm}
\theorembodyfont{\normalfont}
\newtheorem{exo}{Exercice}
\newtheorem{corexo}{Correction de l'exercice}

\usepackage[framemethod=TikZ]{mdframed}

\newenvironment{bloc}[2]{%
    % Paramètres :
    % 1 : header text
    % 2 : color
    \def\FillColor{#2}
    \mdfsetup{%
        backgroundcolor=\FillColor!10,%
        splitbottomskip=10pt,%
        splittopskip=10pt,%
        innertopmargin=3cm,%
        innerbottommargin=20pt,%
        roundcorner=5pt,%
        frametitle={%
            \tikz[baseline=(current bounding box.east),outer sep=0pt,rounded corners=5pt]
            \node[anchor=east,rectangle,fill=\FillColor!80]
            {\strut \color{white} \large\sffamily\scshape \hspace*{.2cm}#1\hspace*{.2cm}};}
    }%
    \mdfsetup{innertopmargin=10pt,linecolor=\FillColor!40,%
        linewidth=1pt,topline=true,
        frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
    \begin{mdframed}[]\relax%
    }{\end{mdframed}\vspace*{1cm}%
}

\newenvironment{exercices}{\begin{bloc}{Exercices}{OrangePen}}{\end{bloc}}

\pagestyle{empty}
\AtBeginShipout{\AtBeginShipoutAddToBox{\Header\Footer}}
\AtBeginShipoutFirst{\Header\Footer}

\color{BlackPen}

\begin{document}    

\begin{exercices}
    \setcounter{corexo}{7}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.15\textwidth}
                \begin{flalign*}
                    A &= a^2 &\\
                    B &= b^3 &
                \end{flalign*}
            \end{minipage}
            \begin{minipage}[t]{.15\textwidth}
                \begin{flalign*}
                    E &= 3c^2 &\\
                    F &= 9+d^3 & \\
                \end{flalign*}
            \end{minipage}

            Aire d'un carré de côté $c$ : \quad $c^2$

            Aire d'un disque de rayon $r$ : \quad $\pi r^2$             
        }
    \end{corexo}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.2\textwidth}
                \begin{flalign*}
                    A &= a+a^2 &\\
                    B &= a^3 &\\
                    C &= 6a^2-a &\\
                    D &= 6a^2 &
                \end{flalign*}
            \end{minipage}
            \begin{minipage}[t]{.2\textwidth}
                \begin{flalign*}
                    E &= 3a^2b &\\
                    F &= 0 &\\
                    G &= 2a^2b^2 &\\
                    H &= (a+b)^2 &
                \end{flalign*}
            \end{minipage}
        }
    \end{corexo}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                    A &= 5\times a \times a &\\
                    B &= 2-b\times b \times b &
                \end{flalign*}
            \end{minipage}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                    C &= a\times a + 2\times b \times b \times b &\\
                    D &= a\times a \times b \times b \times b &
                \end{flalign*}
            \end{minipage}
        }
    \end{corexo}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.2\textwidth}
                \begin{enumerate}[a)]
                    \item $2x$
                    \item $x\div 3$
                    \item $x+13$
                \end{enumerate}
            \end{minipage}
            \begin{minipage}[t]{.2\textwidth}
                \begin{enumerate}[a)]
                    \setcounter{enumi}{3}
                    \item $x-7$
                    \item $3(2+x)$
                    \item $(16-x)\div 3$
                \end{enumerate}
            \end{minipage}
        }

    \vfill  % doesn't fill with orange background till end of \textheight

    \end{corexo}

    \begin{corexo}
        \vspace*{5pt}   % what else to have a bit of space between top of the orange frame and text?
    {\setlength{\abovedisplayskip}{0pt}
        \begin{minipage}[t]{.45\textwidth}
            \begin{enumerate}[A :]
                \item La somme de $x$ et de 7.
                \item Le triple de $x$.
                \item La somme du double de $x$ et de 1.
            \end{enumerate}
        \end{minipage}
        \begin{minipage}[t]{.45\textwidth}
            \begin{enumerate}[A :]
                \setcounter{enumi}{3}
                \item La différence de 5 et du double de $x$.
                \item Le produit de la somme de 3 et de $x$ et de la différence de 3 et de $x$.
                \item La somme du carré de $x$ et de 5.
            \end{enumerate}
        \end{minipage}
    }
    \end{corexo}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                A &= 7+11 = 18 &\\
                B &= 5\times 2 = 10 & \\
                C &= 14+3=17 &
                \end{flalign*}
            \end{minipage}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                D &= 14\times 1,5 = 21 & \\
                E &= 2+2\times 5 = 12& \\
                F &= 15-3\times 1 = 12&
                \end{flalign*}
            \end{minipage}
        }
    \end{corexo}
    \begin{corexo}
        {\setlength{\abovedisplayskip}{0pt}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                A &= 2,5^2 = 6,25&\\
                B &= 5\times 2^2 = 20& \\
                C &= 4+2\times 0^2 = 4&
                \end{flalign*}
            \end{minipage}
            \begin{minipage}[t]{.25\textwidth}
                \begin{flalign*}
                D &= 3^3=27 & \\
                E &= 2\times 5^3=250 & \\
                F &= 15-1^3=14 &
                \end{flalign*}
            \end{minipage}
        }
    \end{corexo}
    \begin{corexo}
    {\setlength{\abovedisplayskip}{0pt}
        \begin{minipage}[t]{.25\textwidth}
            \begin{flalign*}
            C &= 3\times 2+4=10&\\
            D &= 3-2+8=9&
            \end{flalign*}
        \end{minipage}
        \begin{minipage}[t]{.25\textwidth}
            \begin{flalign*}
            E &= 3\times 2-3-2+4 = 5& \\
            F &= 3\times 2 \times 3 = 18&
            \end{flalign*}
        \end{minipage}
    }
    \end{corexo}
\begin{corexo}
    {\setlength{\abovedisplayskip}{0pt}
        \begin{minipage}[t]{.25\textwidth}
            \begin{flalign*}
            C &= 1^2+1+4 = 6 &\\
            D &= 1^2+2\times 1\times 4+4^2=25 &
            \end{flalign*}
        \end{minipage}
        \begin{minipage}[t]{.25\textwidth}
            \begin{flalign*}
            F &= 1^2\times 4=4 & \\
            E &= 1^2+4^2=17 &
            \end{flalign*}
        \end{minipage}
    }
\end{corexo}
\end{exercices}
\end{document}

Current compilation screenshot:

Current compilation screenshot



Related Questions


Why isn't my environment using mdframed working?

Updated June 14, 2017 07:23 AM

Environment with mdframed

Updated July 16, 2019 06:23 AM

Nested mdframed environment problems

Updated March 27, 2015 05:07 AM

Footnotes in multipage environments

Updated March 14, 2016 08:09 AM

create new environment with mdframed and listing

Updated January 31, 2018 10:23 AM