tcolorbox 无法正确打印偏移量?

tcolorbox 无法正确打印偏移量?

编辑:原来是我的 PDF 查看器。


所以我做了这个小改动tcolorbox,并且后续每对规则之间的距离并不匹配所有规则:

http://i.imgur.com/I1lA91z.png

我的代码是这样的:

\documentclass{article}
\usepackage[skins]{tcolorbox}
\definecolor{bg}{HTML}{F8FAFF}
\definecolor{col1}{HTML}{80B2FF} %4 Outer right borderline
\definecolor{col2}{HTML}{99C2FF} %3
\definecolor{col3}{HTML}{B2D1FF} %2
\definecolor{col4}{HTML}{CCE0FF} %1 Outer left borderline
\newdimen\BLW % BorderLine Width
\BLW\dimexpr 5pt\relax
\newdimen\BLS % BorderLine Sep
\BLS\dimexpr 0pt\relax
\newdimen\BLLa % ``Gap'' between first and second line
\BLLa\dimexpr -\BLW-\BLS-(\dimexpr 3\BLW/4)/2\relax\relax
\newdimen\BLLb % between second and third line
\BLLb\dimexpr -\BLW-\BLS-(\dimexpr 3\BLW/4)-\BLS-(\dimexpr 9\BLW/16)/2 \relax\relax\relax
\newdimen\BLLc % between third and fourth line
\BLLc\dimexpr -\BLW-\BLS-(\dimexpr 3\BLW/4) -\BLS-(\dimexpr 9\BLW/16)-\BLS-(\dimexpr 27\BLW/64)/2 \relax\relax\relax\relax

\begin{document}
\begin{tcolorbox}[
  width=\linewidth-6pt,
  frame hidden,
  colback=bg,
  freelance,
  arc=0pt,
  boxrule=0pt,
  frame code={
    \draw[col1,line width=\BLW]  % right
      ([xshift=-\BLW/2]frame.north west) -- ([xshift=-\BLW/2]frame.south west);
    \draw[col2,line width=3\BLW/4] 
      ([xshift=\BLLa]frame.north west) -- ([xshift=\BLLa]frame.south west);
    \draw[col3,line width=9\BLW/16] 
      ([xshift=\BLLb]frame.north west) -- ([xshift=\BLLb]frame.south west);
    \draw[col4,line width=27\BLW/64] 
      ([xshift=\BLLc]frame.north west) -- ([xshift=\BLLc]frame.south west);
  }
]
some stuff
\end{tcolorbox}

BLW: \the\BLW\relax

BLS: \the\BLS\relax

$\frac{3}{4}$ BLW: \the\dimexpr3\BLW/4\relax

$\frac{9}{16}$ BLW: \the\dimexpr9\BLW/16\relax

$\frac{27}{64}$ BLW: \the\dimexpr27\BLW/64\relax

BLLa: \the\BLLa\relax

BLLb: \the\BLLb\relax

BLLc: \the\BLLc\relax

\end{document}

如您所见,这些\dimexpr值实际上是正确的,而边界线/规则的偏移量则不正确。(此偏移量应等于\BLS,但实际上它到处都是。)

为了理解我是如何计算规则的位置来创建关于的静态偏移的\BLS,请考虑这张图片:

http://i.imgur.com/2yVmTp1.png

使用命令打印的值\the显示正确的值,但 tcolorbox

答案1

\dimexpr你的例子没有证明你的断言。\dimexpr计算似乎是准确的,尽管你使用了一种相当冗长的风格,带有冗余的嵌套\dimexpr,可以简化为

\documentclass{article}

\newdimen\BLW % BorderLine Width
\BLW\dimexpr 5pt\relax
\newdimen\BLS % BorderLine Sep
\BLS\dimexpr 1pt\relax
\newdimen\BLLa % ``Gap'' between first and second line
\BLLa\dimexpr -\BLW/2-\BLS-(3\BLW/4)/2\relax


\newdimen\BLLb % between second and third line
\BLLb\dimexpr -\BLW/2-\BLS-(3\BLW/4)-\BLS-(9\BLW/16)/2 \relax


\newdimen\BLLc % between third and fourth line
\BLLc\dimexpr -\BLW/2-\BLS-(3\BLW/4) -\BLS-(9\BLW/16)-\BLS-(27\BLW/64)/2 \relax


\stop

但据推测您的错误是在宽度键中使用了算术表达式,而该表达式无法被解释\dimexpr(如果被解释,则会^出现语法错误)

您的示例不是很简单,并且没有给出预期结果的迹象,所以我无法建议对此进行更改。

相关内容