2

I don't know why, but I can't use decoration with rounded corners. The following MWE fails with ERROR: Dimension too large.:

\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing}
\begin{document}
\begin{standaloneframe}
  \begin{tikzpicture}[main style/.style={
        rectangle,draw,fill=blue!30,decorate,
        decoration={zigzag,segment length=1mm,amplitude=.5mm}
      }]
    % Ok
    \node[main style] at (0,0) {ABC};
    % Fails
    \node[main style, rounded corners] at (0,-1) {DEF};
  \end{tikzpicture}
\end{standaloneframe}
\end{document}
3

This can happen with these types of decorations. If you choose too small a step size or amplitude, or do something like rounded corners, you may receive dimension too large errors. However, to me a zigzag with rounded corners looks like a snake. So maybe this is the way to go.

\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing}
\begin{document}
\begin{standaloneframe}
  \begin{tikzpicture}[main style/.style={
        rectangle,draw,fill=blue!30,decorate,
        decoration={zigzag,segment length=1mm,amplitude=.5mm}
      },round main style/.style={
        rectangle,draw,fill=blue!30,decorate,
        decoration={snake,segment length=1mm,amplitude=.5mm}}]
    % Ok
    \node[main style] at (0,0) {ABC};
    % Fails
    \node[round main style] at (0,-1) {DEF};
  \end{tikzpicture}
\end{standaloneframe}
\end{document}

enter image description here

UPDATE: Thanks for clarifying your request. Here is something that sort of does what you want, I think, and is based on this nice answer by Loop Space as well as Jake's complete sines and my answer to your partner question.

\documentclass[beamer,tikz,preview,border=3.14mm]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing,shapes.geometric,backgrounds}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
% based on https://tex.stackexchange.com/a/25689/121799
% actual code from https://tex.stackexchange.com/a/447546/121799
\pgfdeclaredecoration{zigzag cycle}{initial}{
\state{initial}[
        width=+0pt,
        next state=half up,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
  \state{half up}[
        width=+.25\pgfdecorationsegmentlength,
        next state=big down]
        {\pgfcoordinate{zigzag-cycle-start}{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
        \pgfpathmoveto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
    }
  \state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                   width=+.5\pgfdecorationsegmentlength,
                   next state=big up]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}}
  }
  \state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                 width=+.5\pgfdecorationsegmentlength,
                 next state=big down]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
  }
  \state{center finish}[width=0pt, next state=final]{
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointanchor{zigzag-cycle-start}{center}}
  }
}



\begin{document}
\begin{standaloneframe}
 \begin{tikzpicture}[main style/.style={
        rectangle,draw=none}]
    % avoids the dimension too large error with ordinary zigzags
    \node[save path=\pathA,main style, rounded corners=3mm,inner sep=5pt] at (0,0) {ABC};
    \node[save path=\pathB,main style, rounded corners=3mm,inner sep=5pt] at (5,0) {ordinary zigzag};
    \begin{scope}[on background layer]
    \draw[decorate,decoration={zigzag,segment length=1mm,amplitude=.5mm},fill=blue!30] [use path=\pathA];
    \draw[decorate,decoration={zigzag,segment length=1mm,amplitude=.5mm},fill=blue!30] [use path=\pathB];
    \end{scope}
    % closed zigzag (it is OK to overwrite \pathA and \pathB after they have done their job)
    \node[save path=\pathA,main style, rounded corners=3mm,inner sep=5pt] at (0,-2) {ABC};
    \node[save path=\pathB,main style, rounded corners=3mm,inner sep=5pt] at (5,-2) {zigzag cycle};
    \begin{scope}[on background layer]
    \draw[decorate,decoration={zigzag cycle,segment length=1mm,amplitude=.5mm},fill=blue!30,sharp corners] [use path=\pathA];
    \draw[decorate,decoration={zigzag cycle,segment length=1mm,amplitude=.5mm},fill=blue!30,sharp corners] [use path=\pathB];
    \end{scope}
  \end{tikzpicture}
\end{standaloneframe}
\end{document}

enter image description here

  • Oh... Thanks, but I think that we are not talking about the same thing because when I was thinking about rounded corners, I wanted to round the corners of the original rectangle, not the angles of the final zigzag. So I'd like something like an ellipse with a zigzag decoration, but instead of an ellipse, I want the shape I obtain with the option rectangle, rounded corners. – tobiasBora Aug 24 '18 at 14:13
  • @tobiasBora I see. Sorry about this. To the best of my knowledge this is a not completely solved problem. The main problem is that the rounded corners shines through to the decoration. Here you can find a version that defines a path with rounded corners, stores it and redraws it with the decoration. However, if you want to use the path to fill some area with that trick, as you seem to want in your node, I am not sure that works. – user121799 Aug 24 '18 at 15:13
  • 1
    @tobiasBora I added a somewhat complicated answer based on Loop Space's tricks. – user121799 Aug 24 '18 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.