我正在尝试改变 tccolorbox 框架的外观。装饰与普通的 tikzpicture 配合使用效果很好,但用作 tcolorbox 的装饰时看起来很奇怪。
代码:
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing} % to try using zigzag decoration
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{decorate diamonds/.style={decoration={
markings,
mark=between positions 0 and 1 step #1*sqrt(2) with {
\draw [rotate=45] (-#1/2, -#1/2) rectangle (#1/2, #1/2);
}
}}}
\tikzset{decorate diamonds/.default=2pt}
\begin{tikzpicture}[
decorate diamonds=2pt,
radius=1cm,
]
\draw (0,0) [decorate] --(2, 0)
arc[start angle=90, end angle=0]
-- +(0, -2)
arc[start angle=0, end angle=-90]
-- +(-2, 0)
arc[start angle=270, end angle=180]
-- +(0, 2)
arc[start angle=180, end angle=90]
;
\end{tikzpicture}
\begin{tcolorbox}[
enhanced,
frame style={decorate diamonds=2pt, decorate},
colback=white
]
hi there!
hello!
why hi there!
\end{tcolorbox}
\end{document}
在 tikzpicture 中,装饰看起来符合预期。但在 tcolorbox 中,装饰看起来……很奇怪。就像钻石“折叠”在自己身上一样。有一件事可能提供洞察力的是使用锯齿形装饰,我最初用它来尝试制作这种菱形图案,或者使标记更大。下面是相同代码的输出,但每个菱形的宽度为6pt
:
答案1
\draw
中使用的innermark=between positions 0 and 1 step #1*sqrt(2) with={...}
受 tikz 选项的 (outer) 值的影响。请注意,此选项由选项rounded corners=<dimension>
间接设置为。重置为有效。1mm
tcolorbox
/tcb/arc
sharp corners
顺便说一句,当装饰路径使用非零时,问题是可重现的rounded corners=<dimension>
。而且我必须使用 luatex 来避免“尺寸太大”错误。
\documentclass{article}
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing} % to try using zigzag decoration
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{decorate diamonds/.style={decoration={
markings,
mark=between positions 0 and 1 step #1*sqrt(2) with {
% note the added option "sharp corners"
\draw[sharp corners, rotate=45] (-#1/2, -#1/2) rectangle (#1/2, #1/2);
}
}}}
\tikzset{decorate diamonds/.default=2pt}
\begin{tikzpicture}[
decorate diamonds=2pt,
radius=1cm,
]
\draw (0,0) [decorate] --(2, 0)
arc[start angle=90, end angle=0]
-- +(0, -2)
arc[start angle=0, end angle=-90]
-- +(-2, 0)
arc[start angle=270, end angle=180]
-- +(0, 2)
arc[start angle=180, end angle=90]
;
\end{tikzpicture}
\begin{tcolorbox}[
enhanced,
frame style={decorate diamonds=2pt, decorate},
colback=white
]
hi there!
hello!
why hi there!
\end{tcolorbox}
\end{document}