5

This is a trivial color box, which provided by tcolorbox package:

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}

In XeLaTeX, it works good in even pages, but cause overfull hbox in odd pages: Incorrect color box in XeLaTeX

The twoside class option has been activated and margin parameters are

\oddsidemargin=-10.4mm  
\evensidemargin=-20.4mm 
\topmargin=-35mm        
\textwidth=190mm        
\textheight=275mm 

It appears OK in LaTeX. Is it possible to use correctly in XeLaTeX, too?

Here is the minimal working example:

\documentclass[11pt,a4paper,twoside]{article}

\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{bidi}    

\oddsidemargin=-10.4mm  
\evensidemargin=-20.4mm 
\topmargin=-35mm        
\textwidth=190mm        
\textheight=275mm       

\begin{document}
Text test
\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\newpage
Text test
\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\end{document}
2
  • 1
    Please add a minimal working example (MWE) that illustrates your problem. Commented Jun 26, 2013 at 18:17
  • While creating the MWE, I've detected that the reason is bidi package. If to disable \usepackage{bidi} row, it becomes OK. Personally I don't need bidi package, but if anyone use XeLaTeX, bidi and tcolorbox, question is still opened. Please check MWE in question field. Commented Jun 26, 2013 at 19:37

1 Answer 1

7

I don't know why tcolorbox is indented notwithstanding the fact that it issues \noindent; probably some bad interaction with bidi. You can solve the problem by redefining the noparskip key and setting \parindent to zero (which is set to anyway inside a tcolorbox).

If you use a non zero parskip, you have to redefine accordingly the parskip key.

\documentclass[11pt,a4paper,twoside]{article}
\usepackage[pass,showframe]{geometry}

\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{bidi}    

\tcbset{
  noparskip/.style={before={\par\smallskip\pagebreak[0]\parindent=0pt },
                    after={\par\smallskip}}
}

\begin{document}

Text test

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.\showthe\parindent
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\newpage
Text test

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\end{document}

enter image description here

A different workaround (thanks to Marco Daniel for suggesting it) can be to conditionally add \noindent to the redefinition of \pgfpicture performed by bidi:

\documentclass[11pt,a4paper,twoside]{article}
\usepackage[pass,showframe]{geometry}

\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{bidi}    

\newif\iftcbnoindent
\tcbset{
  noparskip/.style={before={\par\smallskip\pagebreak[0]\noindent\tcbnoindenttrue},
                    after={\par\smallskip}}
}
\makeatletter
\AtBeginDocument{
\@ifpackageloaded{bidi}
 {\def\pgfpicture{%
   \ifmmode\else
     \LTR
     \iftcbnoindent\tcbnoindentfalse\noindent\fi % <-- addition
     \beginL
   \fi
   \origin@pgfpicture}}{}
}
\makeatother

\begin{document}

Text test

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\newpage
Text test

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
\end{document}
2
  • I suggest the following \edef\origparindent{\parindent=\the\parindent} \tcbset{ noparskip/.style={before={\par\smallskip\pagebreak[0]\parindent=0pt }, after={\par\smallskip}}, before upper = {\origparindent}, before lower = {\origparindent}, } Commented Jun 26, 2013 at 20:05
  • @MarcoDaniel If I say \showthe\parindent inside a tcolorbox, I get 0pt, as usual in a \parbox. This might be a good addition to the package, but is another question. Since keys are evaluated after \begin, there should be no difference in behavior.
    – egreg
    Commented Jun 26, 2013 at 20:17

You must log in to answer this question.

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