2

I use a tcolorbox as background for my pictures. The final color is not decided yet. Currently it's green!5!white. One of the pictures shall show a type of pattern like punch holes in a piece of paper. The background shall be visible through these holes. Moreover this piece of paper shall have a shadow and the shadow shall also be visible through these punch holes, but only at the top and left borders. What I get so far:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows}

\begin{document}
    \begin{tikzpicture}[%
        d0/.style={%
            font=\ttfamily},
        d1/.style={%
            minimum width  = 0.50 cm,
            minimum height = 0.75 cm,
            draw,
            fill=green!5!white,
            }
        ]

    \path [fill=white, draw, drop shadow] (-0.4,2.25) rectangle (2.9,8.5);
    \node at (1.25,9){bumpmap};
    \foreach \f [count=\x] in {%
        % percentage signs are necessary,
        % otherwise node style is not recognized correctly
        1,0,1,0,1,1,%
        0,0,0,0,1,0,%
        0,1,1,0,0,0,%
        0,1,0,0,0,1,%
        0,1,0,1,1,0,%
        0,0,0,0,1,1,%
        1,0,1,0,0,0,%
        0,0,1,0,0,1%    
        }{%
        \pgfmathMod{\x-1}{6};
        \edef\myx{\pgfmathresult};
        \pgfmathdiv{\x-1}{6};
        \edef\myy{\pgfmathresult};

        \node [d\f] at (\myx*0.5,8-\myy*0.75) {};
    }
    \end{tikzpicture}
\end{document}

The punch holes are faked in my MWE. I could not manage the evenoddrule with so many holes and I miss also the shadow inside the green holes. Ideas, hints or a solution are very much appreciated.

Many thanks in advance

enter image description here

2
  • Interesting problem, but complex. If the punching holes are really side by side, then there shouldn't be any lines (and shadows) between adjacent holes. Is the layout fixed, a one-time matrix, or does this have to generated flexibly for arbitrary combinations of punchholes? – gernot Feb 6 at 23:53
  • The layout isn't fix in general, but for this one example yes. In the meanwhile I did it as you have mentioned with adjacent boxes. It shows artefacts, thin lines. What's about the one-time matrix? Thanks – Harald Lichtenstein Feb 7 at 13:02
3

As indicated in my comment, I like to post a workaround, which is not perfect and still shows very thin unwanted lines, but it shows at least what I wanted, the punch holes.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{ifthen}
\usetikzlibrary{shadows}

\begin{document}
    \begin{tikzpicture}[even odd rule]

        \begin{scope}[shift={(0,0)}]
            \node at (1.5,9.25){Pattern};
            \foreach \f [count=\x] in {%
                1,0,1,0,1,1,%
                0,0,0,0,1,0,%
                0,1,1,0,0,0,%
                0,1,0,0,0,1,%
                0,1,0,1,1,0,%
                0,0,0,0,1,1,%
                1,0,1,0,0,0,%
                0,0,1,0,0,1%    
                }{%
                \pgfmathMod{\x-1}{6};
                \edef\myx{\pgfmathresult};
                \pgfmathdiv{\x-1}{6};
                \edef\myy{\pgfmathresult};
                
                \ifthenelse {\f=0}
                    {\fill [drop shadow,fill=brown!20!white]
                        (\myx*0.5,8-\myy*0.8) rectangle ++(0.5,0.8);
                    }
                    {\fill [drop shadow,fill=brown!20!white]
                        (\myx*0.5,8-\myy*0.8) rectangle ++(0.5,0.8)
                        (\myx*0.5+0.1,8-\myy*0.8+0.1) rectangle ++(0.3,0.6);
                    }
            \path [draw] (0,2.4) rectangle (3,8.8);
            }
        \end{scope}

    \end{tikzpicture}
\end{document}

enter image description here

1
  • Add the option draw=brown!20!white to you \fill commands. On my screen, the thin lines vanish then. – gernot Feb 9 at 23:39

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.