1

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

0

Solution: use tcolorbox instead of mdframed. Thank you @Ulrike for pointing out.

Description: after @Ulrike comment, I read parts of the tcolorbox documentation. This package appears to be astonishingly complete yet simple to use. The fact is that my frames behave as I expect throughout the pages. The paddings before and after page breaks are handled by the pad at break* parameter and the frame fills the page as much as it can.

The frames are now declared by:

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{skins}

\tcbset{exercices/.style={%
    enhanced,
    before skip=50pt,
    breakable,
    top=20pt,
    title=Exercices,
    pad at break*=7pt,
    fonttitle=\large\bfseries,
    coltitle=white,
    colframe=OrangePen!40,
    colback=OrangePen!10,
    boxrule=1pt,
    attach boxed title to top left={xshift=10pt,yshift=-12pt,yshifttext=-1mm},
    boxed title style={%
        height=24pt,
        valign=center,
        colframe=OrangePen!80,
        colback=OrangePen!80
    }
}}

\newenvironment{exercices}{\begin{tcolorbox}[exercices]}{\end{tcolorbox}}

So the whole code becomes:

\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{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{skins}

\tcbset{exercices/.style={%
    enhanced,
    before skip=50pt,
    breakable,
    top=20pt,
    title=Exercices,
    pad at break*=7pt,
    fonttitle=\large\bfseries,
    coltitle=white,
    colframe=OrangePen!40,
    colback=OrangePen!10,
    boxrule=1pt,
    attach boxed title to top left={xshift=10pt,yshift=-12pt,yshifttext=-1mm},
    boxed title style={%
        height=24pt,
        valign=center,
        colframe=OrangePen!80,
        colback=OrangePen!80
    }
}}

\newenvironment{exercices}{\begin{tcolorbox}[exercices]}{\end{tcolorbox}}

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

\color{BlackPen}

\begin{document}    

    \begin{exercices}
        \setcounter{corexo}{7}
        \begin{corexo}
            \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}
            \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}
            \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}
            \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}
        \end{corexo}
        \begin{corexo}
            \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}
            \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}
            \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}
            \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}
            \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}

As you can see, the result is now what was expected:

frame split accross pages

Finally, as I am really new to tcolorbox, if someone has any advice on how I'm using it, please share.

| 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.