2

enter image description here

I used Mr. Medina's very helpful code (below) but when the example runs from one page to another, there is a line at the bottom of the first page and one on top of the second page. Could someone please help me correct it? Thank you.

\documentclass{book}

\usepackage[many]{tcolorbox}

\usepackage{changepage}

\usepackage{amsthm}

\usepackage{amssymb}

\usepackage{lipsum}


\definecolor{framerule}{RGB}{183,41,41}

\colorlet{tryit}{green!70!black}

\newcommand\RedBox{\textcolor{framerule}{$\square$}}

\newtcolorbox{eoexample}{
  enhanced,
  breakable,
  check odd page,
  toggle left and right,
  boxrule=0pt,
  colback=white,
  arc=0pt,
  outer arc=0pt,
  top=\topsep,
  bottom=\topsep,
  left=0pt,
  right=0pt,
  boxsep=0pt,
  overlay={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east) 
      {You Try It!};
      \draw[framerule] 
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) -- 
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
      \node[inner sep=0pt]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};  
      \draw[framerule] 
        (frame.south west) -- 
        ([xshift=-3pt]box.west);
    \else
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west) 
      {You Try It!};
      \draw[framerule] 
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) -- 
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
      \node[inner sep=0pt]
        (box)
        at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
        {\RedBox};  
      \draw[framerule] 
        (frame.south east) -- 
        ([xshift=3pt]box.east);
    \fi
  }
}


\newtheoremstyle{myexa}% name
  {\topsep}%Space above
  {\topsep}%Space below
  {}%Body font
  {}%Indent amount 1
  {\bfseries}% Theorem head font
  {.}%Punctuation after theorem head
  {.5em}%Space after theorem head 2
  {}%Theorem head spec

\theoremstyle{myexa}

\newtheorem{exa}{Example}

\newenvironment{example}[1][]
  {\begin{eoexample}\begin{exa}}
  {\end{exa}\end{eoexample}}  


\begin{document}

\begin{example}

\lipsum[1-6]

\end{example}

\clearpage

\begin{example}

\lipsum[1]

\end{example}

\end{document}
4

overlay code is applied to non broken boxes but also to each fragment of a broken box. You can decide to which fragment is overlay code applied with options overlay unbroken, overlay first, overlay last, ... (Please look at 4.11 Overlays section in tcolorbox documentation).

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{changepage}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{lipsum}

\definecolor{framerule}{RGB}{183,41,41}

\colorlet{tryit}{green!70!black}

\newcommand\RedBox{\textcolor{framerule}{$\square$}}

\newtcolorbox{eoexample}{
  enhanced,
  breakable,
  check odd page,
  toggle left and right,
  boxrule=0pt,
  colback=white,
  arc=0pt,
  outer arc=0pt,
  top=\topsep,
  bottom=\topsep,
  left=0pt,
  right=0pt,
  boxsep=0pt,
  overlay unbroken ={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east) 
      {You Try It!};
      \draw[framerule] 
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) -- 
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
      \node[inner sep=0pt, anchor=east]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};  
      \draw[framerule] 
        (frame.south west) -- 
        ([xshift=-3pt]box.west);
    \else
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west) 
      {You Try It!};
      \draw[framerule] 
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) -- 
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
      \node[inner sep=0pt, anchor=east, outer sep=0pt]
        (box)
        at (frame.south east)
        {\RedBox};  
      \draw[framerule] 
        ([xshift=-\marginparsep-\marginparwidth]frame.south west) -- 
        ([xshift=-3pt]box.west);
    \fi
  },
  overlay first={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east) 
      {You Try It!};
      \draw[framerule] 
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) -- 
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
    \else
      \node[draw,tryit,fill=white]
      (tryit) 
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west) 
      {You Try It!};
      \draw[framerule] 
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) -- 
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
    \fi
  },
  overlay last={%
    \ifoddpage
      \node[inner sep=0pt]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};  
      \draw[framerule] 
        (frame.south west) -- 
        ([xshift=-3pt]box.west);
    \else
      \node[inner sep=0pt, anchor=east, outer sep=0pt]
        (box)
        at (frame.south east)
        {\RedBox};  
      \draw[framerule] 
        ([xshift=-\marginparsep-\marginparwidth]frame.south west) -- 
        ([xshift=-3pt]box.west);
    \fi
  }
}

\newtheoremstyle{myexa}% name
  {\topsep}%Space above
  {\topsep}%Space below
  {}%Body font
  {}%Indent amount 1
  {\bfseries}% Theorem head font
  {.}%Punctuation after theorem head
  {.5em}%Space after theorem head 2
  {}%Theorem head spec

\theoremstyle{myexa}

\newtheorem{exa}{Example}

\newenvironment{example}[1][]
  {\begin{eoexample}\begin{exa}}
  {\end{exa}\end{eoexample}}  

\begin{document}

\begin{example}
\lipsum[1-6]
\end{example}

\clearpage

\begin{example}
\lipsum[1]
\end{example}

\clearpage

\begin{example}
\lipsum[1]
\end{example}
\end{document}

4 pages

  • Thank you so much :) Also, to make the QED box always shows up on the right of the line, I tried to play around with East, West... in the code but it didn't quite work. Specifically, on page #2, I'd like to have the box on the right of the line. Can you give me some hint? Thank you. – Sean N Mar 25 '15 at 21:26
  • And is there anyway to get rid of the gray lines around the border? – Sean N Mar 25 '15 at 21:41
  • 1
    @SeanN I've updated the code and now, QED is always shows up on the right of the line. The gray lines around the border where a viewer artifact. Now the image has been taken from Adobe Reader and now lines are shown. – Ignasi Mar 26 '15 at 8:19
  • Thank you. You are so resourceful. I'm not sure if I should ask the following question in a different post. But I added the package marginnote to write text right below "You Try it" using this code:\begin{example} \marginnote{\flushleft{\color{framerule}{Simplify $i^{100}$.}}}[-.5cm] \lipsum[1] \marginnote{\flushleft{\color{framerule}{Answer: 1.}}}[-1.2cm] \end{example}. Is there a way for me to include this in the existing code in the preamble so that I don't need to type the whole command every time? I tried it with \newcommand. But I'm hoping to include the block in the "YouTryIt" codes. – Sean N Mar 26 '15 at 9:23
  • 1
    @SeanN I think that what you want it's not too dificult and I'll think about it. But It's better to ask it in a new question because it's not related with this one. – Ignasi Mar 26 '15 at 11:51
4

You have to use your overlay code as overlay unbroken. Also add this code for when the tcolorbox is broken:

  overlay first={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
      {You Try It!};
      \draw[framerule]
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) --
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
    \else
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
      {You Try It!};
      \draw[framerule]
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) --
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
    \fi
  },
  overlay last={%
    \ifoddpage
      \node[inner sep=0pt]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};
      \draw[framerule]
        (frame.south west) --
        ([xshift=-3pt]box.west);
    \else
      \node[inner sep=0pt]
        (box)
        at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
        {\RedBox};
      \draw[framerule]
        (frame.south east) --
        ([xshift=3pt]box.east);
    \fi
  }

MWE

\documentclass{book}

\usepackage[many]{tcolorbox}

\usepackage{changepage}

\usepackage{amsthm}

\usepackage{amssymb}

\usepackage{lipsum}


\definecolor{framerule}{RGB}{183,41,41}

\colorlet{tryit}{green!70!black}

\newcommand\RedBox{\textcolor{framerule}{$\square$}}

\newtcolorbox{eoexample}{
  enhanced,
  breakable,
  check odd page,
  toggle left and right,
  boxrule=0pt,
  colback=white,
  arc=0pt,
  outer arc=0pt,
  top=\topsep,
  bottom=\topsep,
  left=0pt,
  right=0pt,
  boxsep=0pt,
  overlay unbroken={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
      {You Try It!};
      \draw[framerule]
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) --
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
      \node[inner sep=0pt]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};
      \draw[framerule]
        (frame.south west) --
        ([xshift=-3pt]box.west);
    \else
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
      {You Try It!};
      \draw[framerule]
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) --
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
      \node[inner sep=0pt]
        (box)
        at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
        {\RedBox};
      \draw[framerule]
        (frame.south east) --
        ([xshift=3pt]box.east);
    \fi
  },
  overlay first={%
    \ifoddpage
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
      {You Try It!};
      \draw[framerule]
        (frame.north west) -- ([xshift=-3pt]tryit.west);
      \draw[framerule]
        ([xshift=3pt]tryit.east) --
        ([xshift=\marginparsep+\marginparwidth]frame.north east);
    \else
      \node[draw,tryit,fill=white]
      (tryit)
      at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
      {You Try It!};
      \draw[framerule]
        (frame.north east) -- ([xshift=3pt]tryit.east);
      \draw[framerule]
        ([xshift=-3pt]tryit.west) --
        ([xshift=-\marginparsep-\marginparwidth]frame.north west);
    \fi
  },
  overlay last={%
    \ifoddpage
      \node[inner sep=0pt]
        (box)
        at ([xshift=\marginparsep+\marginparwidth]frame.south east)
        {\RedBox};
      \draw[framerule]
        (frame.south west) --
        ([xshift=-3pt]box.west);
    \else
      \node[inner sep=0pt]
        (box)
        at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
        {\RedBox};
      \draw[framerule]
        (frame.south east) --
        ([xshift=3pt]box.east);
    \fi
  }
}


\newtheoremstyle{myexa}% name
  {\topsep}%Space above
  {\topsep}%Space below
  {}%Body font
  {}%Indent amount 1
  {\bfseries}% Theorem head font
  {.}%Punctuation after theorem head
  {.5em}%Space after theorem head 2
  {}%Theorem head spec

\theoremstyle{myexa}

\newtheorem{exa}{Example}

\newenvironment{example}[1][]
  {\begin{eoexample}\begin{exa}}
  {\end{exa}\end{eoexample}}


\begin{document}

\begin{example}

\lipsum[1]

\end{example}

\bigskip

\begin{example}

\lipsum[1-6]

\end{example}


\end{document} 

Output:

enter image description here

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.