1

I'm trying to change how the frame of a tccolorbox looks like. The decoration works fine with a normal tikzpicture, but looks really odd when used as the decoration for a tcolorbox.

Code:

\documentclass{article}

\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing} % to try using zigzag decoration
\usetikzlibrary{decorations.markings}

\begin{document}

    \tikzset{decorate diamonds/.style={decoration={
        markings,
        mark=between positions 0 and 1 step #1*sqrt(2) with {
            \draw [rotate=45] (-#1/2, -#1/2)  rectangle (#1/2, #1/2);
        }
    }}}
    \tikzset{decorate diamonds/.default=2pt}

    \begin{tikzpicture}[
        decorate diamonds=2pt,
        radius=1cm,
    ]
        \draw (0,0) [decorate] --(2, 0)
            arc[start angle=90, end angle=0]
            -- +(0, -2)
            arc[start angle=0, end angle=-90]
            -- +(-2, 0)
            arc[start angle=270, end angle=180]
            -- +(0, 2)
            arc[start angle=180, end angle=90]

            ;
    \end{tikzpicture}

    \begin{tcolorbox}[
        enhanced,
        frame style={decorate diamonds=2pt, decorate},
        colback=white
    ]
        hi there!

        hello!

        why hi there!
    \end{tcolorbox}

\end{document}

Output: 2pt diamonds

In the tikzpicture, the decoration looks as intended. But in the tcolorbox, the decoration looks... strange. It is like the diamonds "fold in" on themselves. One thing that might provide insight is using the zigzag decoration, which I originally used to try to make this diamond pattern, or making the markings larger. Below is the output for the same code, but the width of each diamond is 6pt:

6pt diamonds

5
  • Please extend your code fragment to complete small document, which reproduce your problem that we can test your solutions. – Zarko Jan 24 at 7:40
  • @zarko The snippet is a full document now. – Beelzebielsk Jan 24 at 7:47
  • This does not compile for me. I get '! Dimension too large. <to be read again> \relax l.44 \end{tcolorbox}' Does it work for you? – Plergux Jan 24 at 8:43
  • @Plergux It compiles for me. I am using lualatex for it. One of the answers points out this is necessary, but I am unsure why. – Beelzebielsk Jan 24 at 22:40
  • @Beelzebielsk Ah, I see. That kind of thing is probably also worth a mention when you ask a question. :) – Plergux Jan 25 at 7:13
5

The inner \draw used in mark=between positions 0 and 1 step #1*sqrt(2) with={...} is influenced by the (outer) value of tikz option rounded corners=<dimension>. Note this option is indirectly set to 1mm by tcolorbox option /tcb/arc. Resetting to sharp corners works.

BTW, the problem is reproducible when the decorated path uses non-zero rounded corners=<dimension>. And I have to use luatex to avoid "dimension too large" error.

\documentclass{article}

\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing} % to try using zigzag decoration
\usetikzlibrary{decorations.markings}

\begin{document}
    \tikzset{decorate diamonds/.style={decoration={
        markings,
        mark=between positions 0 and 1 step #1*sqrt(2) with {
            % note the added option "sharp corners"
            \draw[sharp corners, rotate=45] (-#1/2, -#1/2)  rectangle (#1/2, #1/2);
        }
    }}}
    \tikzset{decorate diamonds/.default=2pt}

    \begin{tikzpicture}[
        decorate diamonds=2pt,
        radius=1cm,
    ]
        \draw (0,0) [decorate] --(2, 0)
            arc[start angle=90, end angle=0]
            -- +(0, -2)
            arc[start angle=0, end angle=-90]
            -- +(-2, 0)
            arc[start angle=270, end angle=180]
            -- +(0, 2)
            arc[start angle=180, end angle=90]

            ;
    \end{tikzpicture}

    \begin{tcolorbox}[
        enhanced,
        frame style={decorate diamonds=2pt, decorate},
        colback=white
    ]
        hi there!

        hello!

        why hi there!
    \end{tcolorbox}

\end{document}

enter image description here

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.