尽管使用了 splitbottomskip 和 splittopskip,我仍然无法实现:
- 第 1 页的框架转至 的末尾
\textheight
, - 第 2 页框架内的文本在一个较小的垂直空间后开始。
我看了这个帖子但它建议使用我已经在使用的 splittopmargin(但似乎没有效果)。
然后我又回到了\vspace
我想要避免的噩梦中。
我把所有内容都发布出来,这样你就能看到全部内容了。这是我收集到的几个文件,放在一个 xelatex-compilable 中。我也愿意听取你对代码其他部分的任何评论,因为这一切对我来说都很新。
\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}
当前编译截图:
答案1
解决方案:使用 tcolorbox 而不是 mdframed。感谢@Ulrike 的指出。
描述:在@Ulrike 评论之后,我阅读了部分内容tcolorbox 文档。这个包看起来非常完整,但使用起来却很简单。事实上,我的框架在整个页面中的表现都符合我的预期。分页符前后的填充由参数处理pad at break*
,框架会尽可能地填充页面。
框架现在声明为:
\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}}
所以整个代码变成:
\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}
如您所见,结果正是预期的结果:
最后,由于我对 tcolorbox 还很陌生,如果有人对我如何使用它有任何建议,请分享。