1

Tcolorbox package does not corect recognize odd/even. A primer from here does not work correct any more for twosided documents

\documentclass[]{article}
\RequirePackage{changepage}
\RequirePackage[breakable, many]{tcolorbox}
\usepackage{lipsum}

\newcommand\printpage{%
Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.
}

\NewTColorBox{SomeBox}{+O{}}{%
  breakable, enhanced,
  check odd page,
  lowerbox=ignored,
underlay={%
  if odd page={%
     \draw[red!75!black,line width=1pt]
     (frame.north east)
     --(frame.south west);%
   }{%
     \draw[red!75!black,line width=1pt]
     (frame.north west)
     --(frame.south east);%
   },
},%
  #1
}

\begin{document}

\begin{SomeBox}

\printpage

\lipsum*

\bigskip
\printpage
\end{SomeBox}
\printpage
\end{document}

enter image description here

3

It works if you use the if odd page check directly inside the box code (not inside underlay={...}), like this:

\documentclass{article}
\usepackage{changepage}
\usepackage[breakable, many]{tcolorbox}
\usepackage{lipsum}

\newcommand\printpage{%
  Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.\par
}

\NewTColorBox{SomeBox}{+O{}}{%
  breakable, enhanced,
  check odd page,
  lowerbox=ignored,
  if odd page={
    underlay={
       \draw[blue!75!black,line width=1pt]
       (frame.north east)
       --(frame.south west);
    }
  }{
    underlay={
       \draw[red!75!black,line width=1pt]
       (frame.north west)
       --(frame.south east);
    }
  },
  #1
}

\begin{document}

\begin{SomeBox}
\printpage
\lipsum*[1-3]
\par
\printpage
\end{SomeBox}

\newpage
\begin{SomeBox}
\printpage
\lipsum*[4-6]
\par
\printpage
\end{SomeBox}

\end{document}

Page 1

Page 2

I suppose the reason why /tcb/if odd page doesn't work inside the argument of /tcb/underlay is that /tcb/if odd page is a tcolorbox key, not 〈graphical code〉 (TikZ code, etc.) as expected for the value passed to the /tcb/underlay style.

When a box using the /tcb/breakable key is broken across pages, all parts get the same result for the check, which appears to be done when the box starts. But by using the tcbbreakpart counter, you can make colors or whatever you want alternate inside a breakable box depending on the part number (which starts from 1):

\documentclass{article}
\usepackage{changepage}
\usepackage[breakable, many]{tcolorbox}
\usepackage{lipsum}

\newcommand\printpage{%
  Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.\par
}

\NewTColorBox{SomeBox}{+O{}}{%
  breakable, enhanced,
  check odd page,
  lowerbox=ignored,
  if odd page={
    underlay={
       \ifodd\value{tcbbreakpart}
         \draw[blue!75!black,line width=1pt]
         (frame.north east) -- (frame.south west);
       \else
         \draw[red!75!black,line width=1pt]
         (frame.north west) -- (frame.south east);
       \fi
    }
  }{
    underlay={
       \ifodd\value{tcbbreakpart}
         \draw[red!75!black,line width=1pt]
         (frame.north west) -- (frame.south east);
       \else
         \draw[blue!75!black,line width=1pt]
         (frame.north east) -- (frame.south west);
       \fi
    }
  },
  #1
}

\begin{document}

\begin{SomeBox}
\printpage
\lipsum
\par
\printpage
\end{SomeBox}

\begin{SomeBox}
\printpage
\lipsum
\par
\printpage
\end{SomeBox}

\end{document}

4 in 1

|improve this answer|||||
  • But, unfortunately, if your tcolorbox is break, then the problem remains. My MWE is about breackable tcolorbox – sergiokapone Dec 15 '19 at 16:37
  • This unwanted behawiour was broken in newest versions of tcolorbox, because some previous versions was worked. See tex.stackexchange.com/questions/220153/… – sergiokapone Dec 15 '19 at 16:50
  • AFAICS, this is different: Thomas F. Sturm's answer in your link uses the \ifoddpage macro inside \underlay={...}, this is not the same as the /tcb/if odd page PGF key (no backslash here, only forward slashes)! – frougon Dec 15 '19 at 16:57
  • Yes, that’s different then Thomas F. Sturm's answer. My MWE was an attempt to fix the problem. Thomas F. Sturm's answer doesn't work correctly anymore. – sergiokapone Dec 15 '19 at 17:01
  • Indeed, probably things have changed in how /tcb/underlay is implemented. But did you see my edit? – frougon Dec 15 '19 at 17:05

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.