6

I'm trying to make a custom rectangle to surround my section headers. It's a regular rectangle with the upper-left and lower-right corners "cut" so they're diagonal.

I want it to look like this: pic

I tried to modify the long example from tcolorbox pages 201–202, but am only getting missing corners.

Here's my MWE:

\documentclass[13pt]{extarticle}
\usepackage[paperwidth=9in, paperheight=6in, margin=0.3in, marginparwidth=0.6in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\pagestyle{empty}
\begin{document}
\tcbset{nobeforeafter, colbacktitle=white, colback=white, coltitle=black, width=.5\linewidth}

\begin{tcolorbox}[enhanced, frame code={\path[tcb fill frame] (frame.south west)--([yshift=-5mm]frame.north west)
--([xshift=5mm]frame.north west)--(frame.north east)--([yshift=-5mm]frame.north east)
--([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle;}]
Sample Text
\end{tcolorbox}
\end{document}

But it's looking like this: error picture

Can anyone help me figure out why it's not drawing correctly? Or should I be using something else and not tcolorbox?

7

In your example, the frame is drawn correctly but a white rectangle is then filled above the frame, obscuring the corners. Try a colour other than white to see what is happening more easily.

Do you want something like this?

sample box

If so, you have to hide the interior of the box or else it is placed above the frame, with regular corners. So the fill is passed to the TiKZ command instead and interior hidden is used to block the standard filling of the frame.

\documentclass[13pt]{extarticle}
\usepackage[paperwidth=9in, paperheight=6in, margin=0.3in, marginparwidth=0.6in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\pagestyle{empty}
\begin{document}
  \tcbset{
    nobeforeafter,
    colbacktitle=white,
    colback=white,
    coltitle=black,
    coltext=white,
    fontupper=\sffamily\bfseries\LARGE,
    width=.5\linewidth,
  }

  \begin{tcolorbox}
    [
      enhanced,
      interior hidden,
      frame code={
        \path [tcb fill frame] (frame.south west) -- ([yshift=-5mm]frame.north west) -- ([xshift=5mm]frame.north west) -- (frame.north east) -- ([yshift=5mm]frame.south east) -- ([xshift=-5mm]frame.south east) -- cycle;
      },
    ]
    Sample Text
  \end{tcolorbox}
\end{document}

You might want to look at the options for sharp corners in the package manual, too, in case that offers something easier.

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.