6

For emphasis some key features in my texts I use tcolorbox, which is pushed to the outside border. in normal text this work fine but in itemize environment it is pushed more outside then I desire. Apparently its moving to right/left border accordingly to itemize leftmargin and not of text margin:

\documentclass[12pt]{memoir}
    \usepackage{calc,lipsum}
    \usepackage[T1]{fontenc}
%---------------------------------------------------------------%
    \setstocksize{297mm}{210mm}
    \settrimmedsize{\stockheight}{\stockwidth}{*}
    \settypeblocksize{247mm}{120mm}{*}
    \setulmargins{25mm}{*}{1}
    \setlrmarginsandblock{30mm}{60mm}{*}
\checkandfixthelayout
    \newlength{\marginwidth}
    \setlength{\marginparwidth}{45mm}
    \setlength{\marginparsep}{5mm}
    \setlength{\marginwidth}{\marginparsep+\marginparwidth}
    \setlength{\headwidth}{\textwidth+\marginwidth}
%---------------------------------------------------------------%
    \usepackage[many]{tcolorbox}
    \usetikzlibrary{shapes}
\newtcolorbox{example}[1]{%
    enhanced,
    colback=teal!10, frame hidden, colframe=teal,
    borderline={1pt}{0pt}{teal, sharp corners},
    top=1mm, bottom=1mm, left=1mm, right=1mm,
        check odd page,
            grow to left by =-\marginwidth,
            grow to right by=\marginwidth,
        toggle enlargement=evenpage,
    enlarge top by=5mm,
    arc=0mm,
    width=\textwidth,
    fontupper=\small\sffamily,
    overlay unbroken and first={%
        \node[trapezium,trapezium left angle=90, trapezium right angle=60,
              fill=teal!60!black,inner xsep=2mm,inner ysep=2pt,yshift=-1pt,
              anchor=bottom left corner,
              text=white,font=\small\bfseries\sffamily]
        at (frame.north west)
            {#1};},}

    \begin{document}
\lipsum[2]
    \begin{example}{<title>}
some text
    \end{example}
\lipsum[2]
\begin{itemize}
    \item   the first item text
    \begin{example}{<title>}
Key features of item \dots
    \end{example}
    \item   the second item text
\end{itemize}
    \end{document}

Question: How to convince tcolorbox to be positioned in the itemize environment the same as in normal text ?

enter image description here

3

You can adjust the settings with \@totalleftmargin:

\documentclass[12pt]{memoir}
    \usepackage{calc,lipsum}
    \usepackage[T1]{fontenc}
%---------------------------------------------------------------%
    \setstocksize{297mm}{210mm}
    \settrimmedsize{\stockheight}{\stockwidth}{*}
    \settypeblocksize{247mm}{120mm}{*}
    \setulmargins{25mm}{*}{1}
    \setlrmarginsandblock{30mm}{60mm}{*}
\checkandfixthelayout
    \newlength{\marginwidth}
    \setlength{\marginparwidth}{45mm}
    \setlength{\marginparsep}{5mm}
    \setlength{\marginwidth}{\marginparsep+\marginparwidth}
    \setlength{\headwidth}{\textwidth+\marginwidth}
%---------------------------------------------------------------%
    \usepackage[many]{tcolorbox}
    \usetikzlibrary{shapes}
    \makeatletter
\newtcolorbox{example}[1]{%
    enhanced,
    colback=teal!10, frame hidden, colframe=teal,
    borderline={1pt}{0pt}{teal, sharp corners},
    top=1mm, bottom=1mm, left=1mm, right=1mm,
        check odd page,
            grow to left by =\dimexpr-\marginwidth+\@totalleftmargin
            ,
            grow to right by=\dimexpr\marginwidth+\@totalleftmargin,
        toggle enlargement=evenpage,
    enlarge top by=5mm,
    arc=0mm,
    width=\textwidth,
    fontupper=\small\sffamily,
    overlay unbroken and first={%
        \node[trapezium,trapezium left angle=90, trapezium right angle=60,
              fill=teal!60!black,inner xsep=2mm,inner ysep=2pt,yshift=-1pt,
              anchor=bottom left corner,
              text=white,font=\small\bfseries\sffamily]
        at (frame.north west)
            {#1};},}

    \begin{document}
\lipsum[2]
    \begin{example}{<title>}
some text
    \end{example}
\lipsum[2]


\begin{itemize}
    \item   the first item text 
    \begin{example}{<title>}
Key features of item \dots
    \end{example}
    \item   the second item text
\end{itemize}

\newpage
\lipsum[2]
    \begin{example}{<title>}
some text
    \end{example}
\lipsum[2]


\begin{itemize}
    \item   the first item text
    \begin{example}{<title>}
Key features of item \dots
    \end{example}
    \item   the second item text
\end{itemize}

\end{document}
4

For this case, I would replace toggle enlargement by some direct code:

\documentclass[12pt]{memoir}
    \usepackage{calc,lipsum}
    \usepackage[T1]{fontenc}
%---------------------------------------------------------------%
    \setstocksize{297mm}{210mm}
    \settrimmedsize{\stockheight}{\stockwidth}{*}
    \settypeblocksize{247mm}{120mm}{*}
    \setulmargins{25mm}{*}{1}
    \setlrmarginsandblock{30mm}{60mm}{*}
\checkandfixthelayout
    \newlength{\marginwidth}
    \setlength{\marginparwidth}{45mm}
    \setlength{\marginparsep}{5mm}
    \setlength{\marginwidth}{\marginparsep+\marginparwidth}
    \setlength{\headwidth}{\textwidth+\marginwidth}
%---------------------------------------------------------------%
    \usepackage[many]{tcolorbox}
    \usetikzlibrary{shapes}
\makeatletter
\newtcolorbox{example}[1]{%
    enhanced,
    colback=teal!10, frame hidden, colframe=teal,
    borderline={1pt}{0pt}{teal, sharp corners},
    top=1mm, bottom=1mm, left=1mm, right=1mm,
        code={\checkoddpage\ifoddpage%
          \tcbset{grow to left by=-\marginwidth+\@totalleftmargin,
            grow to right by=\marginwidth+\@totalleftmargin}%
          \else%
          \tcbset{grow to left by=\marginwidth+\@totalleftmargin,
            grow to right by=\marginwidth+\@totalleftmargin}%
          \fi},
    enlarge top by=5mm,
    arc=0mm,
    width=\textwidth,
    fontupper=\small\sffamily,
    overlay unbroken and first={%
        \node[trapezium,trapezium left angle=90, trapezium right angle=60,
              fill=teal!60!black,inner xsep=2mm,inner ysep=2pt,yshift=-1pt,
              anchor=bottom left corner,
              text=white,font=\small\bfseries\sffamily]
        at (frame.north west)
            {#1};},}
\makeatother
    \begin{document}
\lipsum[2]
    \begin{example}{<title>}
some text
    \end{example}
\lipsum[2]
\begin{itemize}
    \item   the first item text
    \begin{example}{<title>}
Key features of item \dots
    \end{example}
    \item   the second item text
\end{itemize}

\clearpage

\lipsum[2]
    \begin{example}{<title>}
some text
    \end{example}
\lipsum[2]
\begin{itemize}
    \item   the first item text
    \begin{example}{<title>}
Key features of item \dots
    \end{example}
    \item   the second item text
\end{itemize}

\end{document}

enter image description here

2

You can adjust the list environments to compensate. I've used enumitem to simplify this. I've also used memoir's facilities to set the margin notes up, which you should certainly do. (No point having it fix the layout if you then go and immediately mess it up again!)

\documentclass[12pt]{memoir}
\usepackage{calc,enumitem,lipsum}
\usepackage[T1]{fontenc}
\setstocksize{297mm}{210mm}
\settrimmedsize{\stockheight}{\stockwidth}{*}
\settypeblocksize{247mm}{120mm}{*}
\setulmargins{25mm}{*}{1}
\setlrmarginsandblock{30mm}{60mm}{*}
\newlength{\marginwidth}
\setmarginnotes{5mm}{45mm}{2.5mm}
\setlength{\marginwidth}{\marginparsep+\marginparwidth}
\setlength{\headwidth}{\textwidth+\marginwidth}
\checkandfixthelayout
\newlength{\myadjustment}
\setlength{\myadjustment}{0pt}
\usepackage[many]{tcolorbox}
\usetikzlibrary{shapes}
\newtcolorbox{example}[1]{%
  enhanced,
  colback=teal!10, frame hidden, colframe=teal,
  borderline={1pt}{0pt}{teal, sharp corners},
  top=1mm, bottom=1mm, left=1mm, right=1mm,
  check odd page,
  grow to left by =-\marginwidth+\myadjustment,
  grow to right by=\marginwidth,
  toggle enlargement=evenpage,
  enlarge top by=5mm,
  arc=0mm,
  width=\textwidth,
  fontupper=\small\sffamily,
  overlay unbroken and first={%
    \node[trapezium,trapezium left angle=90, trapezium right angle=60,
    fill=teal!60!black,inner xsep=2mm,inner ysep=2pt,yshift=-1pt,
    anchor=bottom left corner,
    text=white,font=\small\bfseries\sffamily]
    at (frame.north west)
    {#1};},
}
\newlength{\myorigadjustment}
\setlist{before=\setlength{\myorigadjustment}{\myadjustment}\setlength{\myadjustment}{\leftmargin},after=\setlength{\myadjustment}{\myorigadjustment}}
\begin{document}
  \lipsum[2]
  \begin{example}{<title>}
    some text
  \end{example}
  \lipsum[2]
  \begin{itemize}
    \item   the first item text
    \begin{example}{<title>}
      Key features of item \dots
    \end{example}
    \item   the second item text
  \end{itemize}
\end{document}

adjusted boxes

  • cfr, your solution work only on odd page, on the event the position of tcolorbox box is not pushed to desired position. Ok, now I found out that my adjustment should be added to 'grow to right by' too. Also, i wonder, is your solution is possible without of use 'enumitem' package? – Zarko Dec 8 '14 at 3:57
  • cfr, unfortunately your solution also not work in nested list environment (meaning that i Should define compensation length for leftmargini too?). I wonder, is there a way to tell tcolorbox not to be part of list environment?, i.e. at beginning leave list and on its end return back? – Zarko Dec 8 '14 at 4:15

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.