3

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}

2 Answers 2

4

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

3
  • 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
    Commented Aug 24, 2018 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
    Commented Aug 24, 2018 at 15:13
  • 1
    @tobiasBora I added a somewhat complicated answer based on Loop Space's tricks.
    – user121799
    Commented Aug 24, 2018 at 15:27
1

(I know this is an old question, but I just answered a similar question which led me to this one and I dug around in the PGF code a little ...)

As is explained in other answers, the problem is that the rounded corners is still in force when the decoration is applied and this causes problems. With a path then it is possible to switch off rounded corners once the path has been constructed since it is easy to insert keys at the appropriate juncture. With a node path then all the path construction happens out of sight making it much harder to insert code at the right place.

However, in reading around about decorations then I found the /pgf/every decoration key and this solves everything. In short, by putting the key sharp corners in this key then we can disable the rounded corners just before the decoration is applied and this seems to be the silver bullet for this problem. It's probably safe enough to put this in your document preamble, but it can also be used on a per-path basis.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/447533/86}
\usepackage{tikz}
\usetikzlibrary{
  positioning,
  decorations.pathreplacing,
  decorations.pathmorphing
}

\tikzset{
  disable rounded corners for decorations/.style={
    /pgf/every decoration/.style={
      /tikz/sharp corners
    },
  }
}

\begin{document}
\begin{tikzpicture}[
  main style/.style={
    rectangle,
    draw,
    fill=blue!30,
    disable rounded corners for decorations,
    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{document}

Node with rounded corners and zigzag decoration

(Note, this doesn't fix the Dimension too large errors!)

Here's a bit of a more obvious example:

\node[main style, rounded corners=1cm,minimum size=3cm] at (0,-3) {DEF};

Larger node with rounded corners and zizzag decoration

Left is without the disabling key, right is with.

2
  • 1
    Oh, very interesting! And this solution is simpler than the accepted one. However it seems that this solution poorly handles one part of the decoration, on the right of the top decoration on the two examples (see the 'cut' spike?), while the other solution was not having this issue as far as I could see. Any idea how easy one can solve this issue?
    – tobiasBora
    Commented Aug 31, 2022 at 14:08
  • 1
    @tobiasBora The match-up can be fixed by using the zigzag cycle decoration in the other answer (which was in turn based on answers to other questions, as linked there) which ensures that a full number of zigs (or possibly zags) fit along the path. Commented Aug 31, 2022 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .