可以在 XeLaTeX 中使用 tcolorbox 吗?

可以在 XeLaTeX 中使用 tcolorbox 吗?

这是一个简单的颜色盒,由 tcolorbox 包提供:

\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}

在 XeLaTeX 中,它在偶数页中运行良好,但在奇数页中会导致水平盒子过满: XeLaTeX 中的颜色框不正确

双边类别选项已激活,保证金参数

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

在 LaTeX 中显示正常。在 XeLaTeX 中也能正确使用吗?

以下是最小的工作示例:

\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}

答案1

我不知道为什么tcolorbox缩进,尽管它发出了\noindent; 可能与 有一些不好的交互。您可以通过重新定义键并设置为零(在 内设置为)来bidi解决问题。noparskip\parindenttcolorbox

如果您使用非零 parskip,则必须相应地重新定义键parskip

\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}

在此处输入图片描述

一种不同的解决方法(感谢 Marco Daniel 的建议)是,有条件地添加到执行\noindent的重新定义中:\pgfpicturebidi

\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}

相关内容