Here's an option using tcolorbox
instead of mdframed
; this version takes care of all three requirements:
- Uses braces.
- Braces are placed on the outer margin.
- The box has a width equal to the
\textwidth
; the braces are in the margin area.
The code:
\documentclass{scrbook}\usepackage{fontspec,collect,multido,lipsum}\usepackage{changepage}\strictpagecheck\newcounter{extrait}\newcounter{fiche}\usepackage[framemethod=tikz,usetwoside]{mdframed}\usepackage[many]{tcolorbox}\usetikzlibrary{calc,arrows,decorations.pathreplacing}\newtcolorbox{tcbdecor}[1]{ check odd page, breakable, colback=white, boxrule=0pt, colframe=white, arc=0pt, outer arc=0pt, top=0pt, bottom=0pt, enhanced jigsaw, oversize, overlay={ \ifoddpage \draw[decoration=brace,decorate,line width=1pt] (frame.north east) -- node[rotate=270,above=4pt] {... #1 ...} (frame.south east); \else \draw[decoration={brace,mirror},decorate,line width=1pt] (frame.north west) -- node[rotate=90,above=4pt] {... #1 ...} (frame.south west); \fi },}\newcommand\histoire[2]{% \addtocounter{fiche}{1}% \definecollection{his\thefiche}% \begin{tcbdecor}{#1} \begin{collect*}% {his\thefiche}{}{}% {\minisec{Extrait \addtocounter{extrait}{1}\theextrait : #1}} {} #2 \end{collect*}% \end{tcbdecor}%}\begin{document}\chapter{Tests}\histoire{A}{\lipsum[1-3]}\lipsum[4]\histoire{B}{\lipsum[5-7]}\lipsum[8]\histoire{C}{\lipsum[9-16]}\chapter{Restitutions}\multido{\i=0+1}{\thefiche}{\setcounter{fiche}{1}\addtocounter{fiche}{\i}\includecollection{his\thefiche}}\end{document}
The result:
A zoomed-in image showing one of the boxes on an odd numbered page:
A zoomed-in image showing one of the boxes on an even numbered page:
If you want brackets instead, simply change the overlay
section to
overlay={ \ifoddpage \draw[line width=1pt] ([xshift=-5pt]frame.north east) -- (frame.north east) -- node[rotate=270,above=4pt] {... #1 ...} (frame.south east) -- ([xshift=-5pt]frame.south east); \else \draw[line width=1pt] ([xshift=5pt]frame.north west) -- (frame.north west) -- node[rotate=90,above=4pt] {... #1 ...} (frame.south west) -- ([xshift=5pt]frame.south west); \fi },
With the above example, one now gets
on an odd numbered page, and
on an even numbered one.