答案1
我会雇用杰克的完整正弦在这里修改你的建议,使之也可以用于tcolorbox
\documentclass[a4paper,12pt]{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{decorations}
\begin{document}
\pgfdeclaredecoration{complete sines}{initial}
{
\state{initial}[
width=+0pt,
next state=sine,
persistent precomputation={\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{sine}[width=\pgfdecorationsegmentlength]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}{}
}
\tikzset{oldfashioned sines/.style={very thick,line cap=rect,% <- thanks to quark67!
decorate,decoration={complete sines,segment length=#1,path has corners}},
oldfashioned sines/.default=9.5pt}
\newtcolorbox{Caution}{%
width=140pt,height=40pt,
colback=white,halign=flush center,valign=center,
enhanced,% jigsaw, breakable, % allow page breaks
frame hidden, % hide the default frame
overlay={%
\draw[oldfashioned sines]
(frame.south west) rectangle (frame.north east);
\draw[oldfashioned sines]
([xshift=1pt,yshift=0.4pt]frame.south west) rectangle ([xshift=1pt,yshift=0.4pt]frame.north east);
},
% paragraph skips obeyed within tcolorbox
parbox=false,
}
\begin{Caution}
\textbf{Caution}
\end{Caution}
\begin{tikzpicture}
\draw[oldfashioned sines]
(0,0) rectangle (140pt,40pt)
node[pos=0.5] {\textbf{CAUTION}};
\end{tikzpicture}
\begin{tikzpicture}
\draw[oldfashioned sines]
(0,0) rectangle (140pt,40pt)
node[pos=0.5] {\textbf{CAUTION}};
\draw[oldfashioned sines]
(1pt,0.4pt) rectangle (141pt,40.4pt) ;
\end{tikzpicture}
\end{document}
我要感谢 quark67 提出的好建议添加line cap=rect
。
附录:尝试满足您的要求。它带有一个symmetric sines
不同于杰克的完整正弦因为振荡次数是半整数。因此,结果是在关于通过路径中间的轴的反射下对称的。
\documentclass[a4paper,12pt]{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{decorations}
\begin{document}
\pgfdeclaredecoration{symmetric sines}{initial}
{
\state{initial}[
width=+0pt,
next state=sine,
persistent precomputation={
\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength /
(int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)+0.5)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{sine}[width=\pgfdecorationsegmentlength]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
\state{final}[width=\pgfdecorationsegmentlength]{
\pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
\pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
}
}
\tikzset{oldfashioned sines/.style={very thick,line cap=rect,% <- thanks to quark67!
decorate,decoration={symmetric sines,segment length=#1,path has corners}},
oldfashioned sines/.default=9.5pt}
\def\LstAnchors{"south west","south east","north east","north west"}
\newtcolorbox{Caution}{%
width=140pt,height=40pt,
colback=white,halign=flush center,valign=center,
enhanced,% jigsaw, breakable, % allow page breaks
frame hidden, % hide the default frame
overlay={%
\foreach \XX [count=\YY,remember=\XX as \LastXX (initially north west)]
in {south west,south east,north east,north west}
{\ifodd\YY
\draw[oldfashioned sines] (frame.\LastXX) -- (frame.\XX);
\draw[oldfashioned sines] ([xshift=1pt,yshift=0.4pt]frame.\LastXX) -- ([xshift=1pt,yshift=0.4pt]frame.\XX);
\else
\draw[oldfashioned sines] (frame.\XX) -- (frame.\LastXX);
\draw[oldfashioned sines] ([xshift=1pt,yshift=0.4pt]frame.\XX) -- ([xshift=1pt,yshift=0.4pt]frame.\LastXX);
\fi}
},
% paragraph skips obeyed within tcolorbox
parbox=false,
}
\begin{Caution}
\textbf{CAUTION}
\end{Caution}
\end{document}