Search code examples
latex

Remove the rounded corners of an inner frame in a tcolorbox


I have the following LaTeX code which creates a warning message box using tcolorbox and puts a warning icon (the triangle warning sign) on the west side of the outer frame but in my test case instead of that warning sign I have used example-image-a from mwe package so that you might be able to run easily the example without downloading any additional file

Here is the code:

\documentclass[11pt]{book}
\usepackage[default]{opensans}
\usepackage{alltt}
\usepackage[listings,skins,most]{tcolorbox}
\usepackage{xcolor}
\usepackage{graphicx}

\definecolor{WarningBoxBg}{HTML}{000000}
\newtcolorbox{WarningBox}[1][]{%
  enhanced,
  boxsep=8pt,
  colback=white,
  colframe=WarningBoxBg,
  boxrule=0.25pt,
  leftrule=35pt,
  overlay unbroken and first ={%
    \node[rotate=0,
          anchor=center,
          minimum width=1cm,
          font=\Large\sffamily\bfseries,
          xshift=17.5pt,
          white]
          at (frame.west) {%
            \includegraphics[width=11mm]{example-image-a}
    };
  }
}

\begin{document}
\begin{WarningBox}
  This is my warning message!
  \begin{itemize}
  \item line-01
  \item line-02
  \item line-03
  \item line-04
  \item line-05
  \end{itemize}
\end{WarningBox}
\end{document}

Is there any way to remove the rounded corner of only the inner frame (the one which includes items list) and doing so only on the west(left) side of it?

Thanks in advance.


Solution

  • You can manually draw the interior to control which corners should be sharp and which rounded:

    \documentclass[11pt]{book}
    \usepackage[default]{opensans}
    \usepackage{alltt}
    \usepackage[listings,skins,most]{tcolorbox}
     \tcbuselibrary{hooks}
    \usepackage{xcolor}
    \usepackage{graphicx}
    
    \definecolor{WarningBoxBg}{HTML}{000000}
    \makeatletter
    \newtcolorbox{WarningBox}[1][]{%
      enhanced,
      boxsep=8pt,
      colback=white,
      colframe=WarningBoxBg,
      boxrule=0.25pt,
      leftrule=35pt,
      interior hidden,
      underlay={
        \fill[tcbcolback] (interior.south west) -- (interior.north west) [rounded corners=\kvtcb@arc] -- (interior.north east) -- (interior.south east) [sharp corners] -- cycle;
      },
      overlay unbroken and first ={%
        \node[rotate=0,
              anchor=center,
              minimum width=1cm,
              font=\Large\sffamily\bfseries,
              xshift=17.5pt,
              white]
              at (frame.west) {%
                \includegraphics[width=11mm]{example-image-a}
        };
      }
    }
    \makeatother
    
    \begin{document}
    \begin{WarningBox}
      This is my warning message!
      \begin{itemize}
      \item line-01
      \item line-02
      \item line-03
      \item line-04
      \item line-05
      \end{itemize}
    \end{WarningBox}
    \end{document}
    

    enter image description here