0

I would like to expect the framebox (like 1B) in the top of the each page when exercise environment is started to ending the exercise environment (i.e., page 2 and 3 only and not page 1, because exercise is started middle of the page 1). Please find the screenshot below:

![enter image description here][1]

My MWE IS:

\documentclass{book}
\usepackage[driver=none]{geometry}
\usepackage{fancyhdr}
\usepackage[tikz]{mdframed}
\geometry{
  paperwidth=190mm,
  paperheight=256mm,
  asymmetric,
  left=20mm,
  right=20mm,
  top=22.5mm,
  bottom=15mm,
  headsep=10.5mm,
  footskip=4mm,
  marginparsep=2mm,
  headheight=21pt
}
\usepackage[cam,a4,center,pdflatex]{crop}
\usepackage{lipsum}
\newcounter{exercise}
\newenvironment{exercise}[1][]{
  \stepcounter{exercise}%
  \mdfsetup{%
    backgroundcolor=green,
    linecolor=blue,%
    linewidth=2pt,
    frametitlerule=true,
    frametitlerulewidth=2.5pt,
  }\relax
  \begin{mdframed}%
}{%
  \end{mdframed}%
}
\begin{document}
\chapter{Chapter Titlte}
\lipsum[1]
\begin{exercise}
\lipsum[1-12]
\end{exercise}
\lipsum[6-14]
\end{document}
4

Using tcolorbox again:

\documentclass{book}
\usepackage[driver=none]{geometry}
\usepackage{ifoddpage}
\usepackage[many]{tcolorbox}
\usetikzlibrary{backgrounds}
\geometry{
  paperwidth=190mm,
  paperheight=256mm,
  asymmetric,
  left=20mm,
  right=20mm,
  top=22.5mm,
  bottom=15mm,
  headsep=10.5mm,
  footskip=4mm,
  marginparsep=2mm,
  headheight=21pt
}
\usepackage[cam,a4,center,pdflatex]{crop}
\usepackage{lipsum}
\newtcolorbox[auto counter]{exercise}[2][]{%
colback=green,
colframe=blue,
arc=0pt,
toprule=2.5pt,
bottomrule=2.5pt,
boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=2pt,
breakable,
enhanced jigsaw,
fonttitle=\fontsize{25}{17}\selectfont\bfseries,
title=\strut Exercise~\thetcbcounter: #2,
%grow to left by=-0.2in,
%enlarge left by=0.2in,
%enlarge right by=-0.4in,
   overlay middle and last={
           \checkoddpage
     \ifoddpage
     \node[anchor=north west,align=left,text width=1.5in,font=\Large\bfseries]
        at ([shift={(2ex,-0.55ex)}]frame.north east) (a) {\thetcbcounter};
     \begin{scope}[on background layer]
           \fill[green!30] (a.south west) to[bend left] (a.north west) -- +(2in,0) |- (a.south west);
     \end{scope}
     \else
     \node[anchor=north east,align=right,text width=1.5in,font=\Large\bfseries]
        at ([shift={(-2ex,-0.55ex)}]frame.north west) (b) {\hfill\thetcbcounter};
     \fi
         \begin{scope}[on background layer]
           \fill[green!30] (b.north east) to[bend left] (b.south east) -- +(-2in,0) |- (b.north east);
         \end{scope}
           },
    before=\vskip\itemsep\noindent
#1}

\begin{document}
\chapter{Chapter Titlte}
\lipsum[1]
\begin{exercise}{}
\lipsum[1-12]
\end{exercise}
\lipsum[6-14]
\end{document}

enter image description here

enter image description here

| improve this answer | |
  • Nice. I don't see any difference between overlay middle and overlay last, so you can save some typing with overlay middle and last. – Ignasi Nov 27 '14 at 11:27
  • I think overlay middle and last doesn't include the first segment, but I could be wrong. – Ignasi Nov 27 '14 at 13:20
  • @Ignasi Yes, But I preferred the long version though. Easy to control. Discard my previous comment, it is meaning less. :) – user11232 Nov 27 '14 at 13:24
  • @Harish: How to set oddside and evenside to display the values and also i have tried fonttitle=\fontsize{15}{17}\selectfont to increase the fontsize. But it's not working. how to achive this. – Balaji Nov 27 '14 at 14:43
  • @Harish: If exercise is starting in newpage (not middle of the page) how to print the values in marginpar? – Balaji Nov 28 '14 at 14:22

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.