2

I'm trying to make a shaped box to hold arbitrary content and I'm using tcolorbox with code I adapted for my purposes from another question. So far I have:

\documentclass[20pt, a4paper]{article}

\usepackage{color}
\usepackage{tcolorbox}
\usepackage{lipsum}

\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newtcolorbox{mybox}{
    left=15pt,
    top=15pt,
    bottom=15pt,
    right=15pt,
    skin=freelance,
    frame code={%
        \begin{pgfonlayer}{background}
            \draw[line width=4pt,color=purple,fill=purple]($(frame.north west) + (15pt, 0pt)$)
                -- (frame.north east)
                -- ($(frame.south east) + (0pt, 15pt)$)
                -- ($(frame.south east) + (-15pt, 0pt)$)
                -- (frame.south west)
                -- ($(frame.north west) + (0pt, -15pt)$)
                -- cycle;

        \end{pgfonlayer}
    },
}

\begin{document}

\begin{mybox}
\lipsum[1]
\end{mybox}

\end{document}

I would like some way to fully fill the shape formed with a solid color without going outside the lines, but behind the content to be displayed. Using the colback option creates a rounded rectangle box of color that goes outside the lines at points and doesn't quite reach the corners at others. However if I try and use the fill option for the shape then it is either filled and blocking out the text, or entirely behind the background color box (depending on which layer I put the frame code on).

  • I think, you have to apply some similar scheme for interior code=... – user31729 Sep 4 '16 at 20:55
  • @ChristianHupfer Hmmm, I'll look into that tomorrow. I found the manual, so that'll give me something to look for and poke at. – Jake Conkerton-Darby Sep 4 '16 at 20:56
  • Needless to load color: tcolorbox loads pgf, which loads xcolor. – Bernard Sep 4 '16 at 21:20
1

Basically the same method has to be applied for interior code, with adjusted vertices, however!

\documentclass[20pt, a4paper]{article}


\usepackage[skins]{tcolorbox}
\usepackage{lipsum}

\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newtcolorbox{mybox}{%
    left=15pt,
    top=15pt,
    bottom=15pt,
    right=15pt,
    skin=enhanced jigsaw,
    frame code={%
      \begin{pgfonlayer}{background}
        \draw[line width=4pt,color=purple,fill=purple]($(frame.north west) + (15pt, 0pt)$)
        -- (frame.north east)
        -- ($(frame.south east) + (0pt, 15pt)$)
        -- ($(frame.south east) + (-15pt, 0pt)$)
        -- (frame.south west)
        -- ($(frame.north west) + (0pt, -15pt)$)
        -- cycle;
      \end{pgfonlayer}
    },
    interior code={%
      \draw[line width=4pt,color=purple,fill=white!90!black]($(frame.north west) + (15pt, -4pt)$) -- ($(frame.north east) + (-4pt,-4pt)$) 
      -- ($(frame.south east) + (-4pt, 15pt)$)  
      -- ($(frame.south east) + (-15pt, 4pt)$)
      -- ($(frame.south west) + (4pt, 4pt)$)
      -- ($(frame.north west) + (4pt, -15pt)$)
      -- cycle;
    }
}

\begin{document}

\begin{mybox}
\lipsum[1]
\end{mybox}

\end{document}

enter image description here

  • I had time to just quickly try this and it works absolutely fine. Thank you very much :D – Jake Conkerton-Darby Sep 4 '16 at 22:11
  • @JakeConkerton-Darby: For a easier setup, the explicit lengths should be stored in length macros -- it is easier to change the parameters then in a single place instead of changing all the 15pt etc. statements. – user31729 Sep 4 '16 at 22:24
  • Ooh, good idea. I've done very little in the way of variety of LaTeX documents, and tips like this are much appreciated. – Jake Conkerton-Darby Sep 4 '16 at 22:28

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.