1

Based on this code, I added a title but now I face the problem that the margins are ignored when I use book or scrbook with the twoside option.

\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}

What's going wrong here or better what does I need to do to make it working?

closed as unclear what you're asking by Mensch, Przemysław Scherwentke, Jesse, Mike Renfro, Zarko May 24 '16 at 4:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    leftmargin and rightmargin may be responsible. Quoting the mdframed manual: »Many books are written in twoside mode. In those cases it’s better to set the margins related to the site. Instead of the explained options leftmargin and rightmargin you can work with the options outermargin and innermargin – clemens Oct 4 '13 at 15:23
  • @cgnieder outermargin seems to have no influence and innermargin (only) shifts the left column under the right one. Any other ideas? – susis strolch Oct 7 '13 at 16:47
  • Indeed the options don't seem to work as expected... Maybe ask @MarcoDaniel about this? – clemens Oct 7 '13 at 16:59

Browse other questions tagged or ask your own question.