9

Technical manuals from the 1960s and 1970s sometimes had eye-catching CAUTION boxes surrounded by wavy or curly lines.

CAUTION CAUTION

My best attempt at re-creating this is not ideal as I can't get the snake to line up on all corners:

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

CAUTION bad

I would also be willing to use any other package which can produce fancy boxes with borders.

Mass
  • 398

1 Answers1

14

I would employ Jake's complete sines here to modify your proposal to something that can also be used in a 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}

enter image description here

I'd like to thank quark67 for the great suggestion to add line cap=rect.

ADDENDUM: An attempt to address your request. It comes with a "new" decoration symmetric sines that differ from Jake's complete sines in that the number of oscillations is half-integer. Therefore the result is symmetric under reflections about an axis that runs through the middle of the path.

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

enter image description here

  • The question is what you want to achieve. Do you want to have such boxes in the text? If so, I will be happy to turn this into a tcolorbox. –  Apr 18 '19 at 02:57
  • 1
    For a slightly better end of the decoration on the bottom left corner (when you magnified the picture), add line cap=rect in the options of \draw. – quark67 Apr 18 '19 at 02:58
  • @quark67 That's an excellent suggestion, thanks! –  Apr 18 '19 at 03:01
  • Looks very nice. Indeed I am interested in headers, not inline with text. Is it possible to have the ends line up symmetrically (like in the first picture of the question) instead of in a counter-clockwise fashion? – Mass Apr 22 '19 at 18:29
  • @Mass I am not sure I understand your request but I added something which I thought may be what you want. If not, please try to explain it in more detail. –  Apr 22 '19 at 21:14
  • @marmot I don't quite see a difference of your update. My request was the following; desired corner: https://i.stack.imgur.com/y4kPk.png answer's corner: https://i.stack.imgur.com/zLEpi.png They meet at a different phase of the sine wave – Mass Apr 22 '19 at 22:22
  • @Mass I added a new version with a "new" decoration symmetric sines. –  Apr 23 '19 at 16:10
  • This is very nice! But how do I get to scale this box with the size of the text that I put into it? I tried putting a long text in the box and it messes up. I would ideally like the box to be the whole columnwidth of the page and be of the same height as the text centered inside it. – Student Jan 09 '24 at 12:22