基于这代码,我添加了一个标题,但是现在我面临的问题是,当我使用带有 twoside 选项的 book 或 scrbook 时,边距会被忽略。
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{multicol}
\setlength{\columnsep}{-2pt}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\tikzset{titregris/.style = {draw=gray, thick, fill=white, text=black, rectangle, rounded corners, right, minimum height=.7cm}}
\makeatletter
\mdfdefinestyle{exercisestyle}{%
outerlinewidth=1em,outerlinecolor=white,%
leftmargin=-1em,rightmargin=-1em,%
middlelinewidth=1.2pt,roundcorner=5pt,linecolor=gray,
backgroundcolor=black!10,
skipabove={0.2pt},
innertopmargin=\baselineskip,
needspace=3\baselineskip,
frametitlefont=\sffamily\bfseries,
singleextra={%
\node[titregris,xshift=1cm] at (P-|O) %
{~\mdf@frametitlefont{Text}\hbox{~}};
},
firstextra={%
\node[titregris,xshift=1cm] at (P-|O) %
{~\mdf@frametitlefont{Test}\hbox{~}};
},
}
\makeatother
\makeatletter
\let\old@page@sofar\page@sofar
\let\old@box\box
\let\old@rlap\rlap
\def\page@sofar{%
\let\box\colorcolumn
\def\rlap{\let\box\old@box\old@rlap}%
\old@page@sofar
}
\def\colorcolumn#1{%
\ifnum#1=\mult@rightbox
\def\zz{\begin{mdframed}[skipabove={11.5pt},innertopmargin=\baselineskip,linecolor=gray,middlelinewidth=1.2pt,roundcorner=5pt,leftline=false,backgroundcolor=black!10]}%
\fi
\ifnum#1=\numexpr\mult@rightbox+2\relax
\def\zz{\begin{mdframed}[style=exercisestyle, rightline=false]}%
\fi
\ifnum#1=\numexpr\mult@rightbox+4\relax
\def\zz{\begin{mdframed}[skipabove={11.5pt},innertopmargin=\baselineskip,linecolor=gray,middlelinewidth=1.2pt,rightline=false,leftline=false,backgroundcolor=black!10]}%
\fi
\kern\dimexpr-15pt\relax
{\let\box\old@box\vtop{%
\zz{%
\hbox{\box#1\llap{\phantom p}}}%
\end{mdframed}}}%
\kern\dimexpr-15pt\relax
}
\makeatother
\begin{document}
\begin{multicols}{2}
\blindtext\blindtext
\end{multicols}
\begin{multicols}{2}
\blindtext\blindtext\blindtext\blindtext
\end{multicols}
\end{document}
这里出了什么问题或者我需要做什么才能使其正常工作?