旧式“警告”框

旧式“警告”框

20 世纪 60 年代和 70 年代的技术手册有时会出现引人注目的“警告”框,周围是波浪线或卷线。

警告 警告

我尽了最大努力重新创建这个,但并不理想,因为我无法让蛇在所有角落排列整齐:

\begin{tikzpicture}
    \draw[very thick,decorate,
        decoration={snake,segment length=9.5pt}]
        (0,0) rectangle (140pt,40pt)
        node[pos=0.5] {\textbf{CAUTION}};
\end{tikzpicture}

小心坏

我还愿意使用任何其他可以生产带边框的精美盒子的包装。

答案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}

在此处输入图片描述

相关内容