5

I created some fancy tcolorbox for writing solutions of the problems:

\documentclass{scrartcl}
\usepackage[breakable, many]{tcolorbox}
\usepackage{changepage}
\usepackage{lipsum}
\NewTColorBox[auto counter,number within=section]{solution}{+O{}}{%
    breakable, enhanced,sharpish corners, colframe=blue!50,colback=white,coltitle=blue!60!black,
    fonttitle=\itshape\bfseries, parbox = false,
    check odd page,toggle left and right,
    boxrule=0.3mm,top=0mm,bottom=0mm,left=2.1cm,right=1mm,
    %grow to right by=1cm,
    %toprule=1mm,
    overlay={%
        \ifoddpage%
        \draw[red!75!black,line width=1pt]
        ([xshift=2.02cm]frame.north west)--([xshift=2.02cm]frame.south west);%
        \else%
        \draw[red!75!black,line width=1pt]
        ([xshift=-1.95cm]frame.north east)--([xshift=-1.95cm]frame.south east);%
        \fi%
        },
    underlay={\begin{tcbclipinterior}
            \draw[help lines,step=5mm,blue!20!white,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
            \end{tcbclipinterior}},
        title={solution},
        label={},
        attach title to upper=\quad,
        after upper={\par\hfill%
            {}},
        lowerbox=ignored,
    }

\begin{document}

        \begin{solution}
        \lipsum[1-40]
        \end{solution}

\end{document}

enter image description here

I need the same tcolorbox with the possibility of margin notes behind the red line. It would be nice if the field behind the red line will coincide with the actual size of the current page margins

1
  • Do you want the notes in the margins of the page? Note that the width allowed for marginal notes is typically less than the width of (the relevant margin minus the distance separating the notes from the text). If, say, the margin was 25mm, the separation might be 5mm and the marginal notes might be 10mm or whatever. (Or the marginal notes might be set up as part of the text body, depending on how you configure the page layout.)
    – cfr
    Jan 1, 2015 at 2:51

1 Answer 1

9

I'm not sure if the following is the solution you are looking for. The box stretches into the page margin and marginnote is used to add margin notes:

\documentclass[twoside]{scrartcl}
\usepackage[breakable, many]{tcolorbox}
\usepackage{changepage}
\usepackage{lipsum,marginnote}

\NewTColorBox[auto counter,number within=section]{solution}{+O{}}{%
  breakable, enhanced,sharpish corners, colframe=blue!50,colback=white,coltitle=blue!60!black,
  fonttitle=\itshape\bfseries, parbox = false,
  check odd page,
  boxrule=0.3mm,top=0mm,bottom=0mm,
  left=1mm,
  right=\the\dimexpr\marginparsep+\marginparwidth+1mm\relax,
  grow to right by=\the\dimexpr\marginparsep+\marginparwidth+1mm\relax,
  toggle left and right,
  toggle enlargement,
  underlay={%
    \begin{tcbclipinterior}
      \draw[help lines,step=5mm,blue!20!white,shift={(interior.north west)}]
      (interior.south west) grid (interior.north east);
      \ifodd\value{page}%
        \draw[red!75!black,line width=1pt]
        ([xshift=-\the\dimexpr\marginparsep/2+\marginparwidth+2mm\relax]frame.north east)
        --([xshift=-\the\dimexpr\marginparsep/2+\marginparwidth+2mm\relax]frame.south east);%
      \else%
        \draw[red!75!black,line width=1pt]
        ([xshift=\the\dimexpr\marginparsep/2+\marginparwidth+2mm\relax]frame.north west)
        --([xshift=\the\dimexpr\marginparsep/2+\marginparwidth+2mm\relax]frame.south west);%
      \fi%
    \end{tcbclipinterior}},
  title={solution},
  label={},
  attach title to upper=\quad,
  after upper={\par\hfill%
      {}},
  lowerbox=ignored,
  #1
  }

\begin{document}

  \begin{solution}
  \lipsum[1]
  \marginnote{\small Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
  \lipsum[2-8]
  \marginnote{\small Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
  \lipsum[9-40]
  \end{solution}

\end{document}

enter image description here enter image description here

2
  • Do you know how I can pass some arguments to the \NewTcolorBox by some conditions, say \if@twoside\...\fi ? Jan 2, 2015 at 13:17
  • @sergiokapone you can use the code option like code={\if@twoside\tcbset{...}\else\tcbset{...}\fi} Jan 2, 2015 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .