1

I have the code of tcolorbox as below

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{vietnam}
\newcounter{dang}\setcounter{dang}{0}
\renewcommand{\thedang}{\arabic{dang}}
\newtcolorbox{dang}[1]{enhanced, breakable,
    before skip=2mm,after skip=2mm,
    colback=white,colframe=blue!40!black,boxrule=0.5mm,
    attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,arc is angular,
    boxed title style={frame code={
            \path[fill=tcbcol@back!30!black]
            ([yshift=-1mm,xshift=-1mm]frame.north west)
            arc[start angle=0,end angle=180,radius=1mm]
            ([yshift=-1mm,xshift=1mm]frame.north east)
            arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=tcbcol@back!60!black,right color=tcbcol@back!60!black,
            middle color=tcbcol@back!80!black]
            ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
            [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
            -- (frame.south east) -- (frame.south west)
            -- ([xshift=-1mm,yshift=-1mm]frame.north west)
            [sharp corners]-- cycle;
        },interior engine=empty,
    },colbacktitle=blue!40!black,breakable,
    fonttitle=\bfseries,
    title={#1}
    \addcontentsline{toc}{subsubsection}{#1}
}

\begin{dang}{Cộng 2 số phức}
        Ta có $ z=a+bi $ và $ z'=a'+b'i $ khi đó $ z+z'=a+a'+(b+b')i $
    \end{dang}

\end{document}

I want to hide or show the title of the box which is blue background with white contents. How can I do that? Thank you

3

It's not quite clear from your question, so I've made a few assumptions about what you want.

The usual way not to show the title box is simply not to include title={…} in your box options.

But in the way you are currently doing things, this means you have to pull the \addcontentsline out of the box options and into the argument of each box you want to have in the table of contents. IMHO, this is less than ideal.

tcolorbox is able to automatically put each box in the table of contents using the box title as the entry. Unfortunately, if no title is given, it puts in the name of the box environment (i.e., dang)! Again, this is not really ideal, as I would assume that in your case, you would want boxes without a title not to be included in the table of contents.

My compromise is to follow standard LaTeX behaviour and create two box environments (dang and dang*) where only dang is included in the table of contents. Both can have a title specified.

It's also possible to automatically number boxes, but I haven't done this below as I'm not sure what you want.

MWE

\documentclass[12pt,a4paper]{article}

\usepackage{varwidth}
\usepackage[most]{tcolorbox}
\usepackage[utf8]{vietnam}

\tcbset{%
  dang/.style={
    enhanced, breakable,
    before skip=2mm, after skip=2mm,
    colback=white, colframe=blue!40!black,
    boxrule=0.5mm, arc is angular,
    attach boxed title to top left={xshift=1cm, yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={frame code={
        \path[fill=tcbcolback!30!black]
          ([yshift=-1mm,xshift=-1mm]frame.north west)
          arc[start angle=0,end angle=180,radius=1mm]
          ([yshift=-1mm,xshift=1mm]frame.north east)
          arc[start angle=180,end angle=0,radius=1mm];
        \path[left color=tcbcolback!60!black, right color=tcbcolback!60!black,
            middle color=tcbcolback!80!black]
          ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
          [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
          -- (frame.south east) -- (frame.south west)
          -- ([xshift=-1mm,yshift=-1mm]frame.north west)
          [sharp corners]-- cycle;
        },
      interior engine=empty},
    colbacktitle=blue!40!black,
    fonttitle=\bfseries}}

\newtcolorbox[list inside=toc]{dang}[1][]{dang,#1}
\newtcolorbox{dang*}[1][]{dang,#1}

\begin{document}

\tableofcontents

\section{A section}

\subsection{A subsection}

\begin{dang}[title=Cộng 2 số phức]
  Ta có $ z=a+bi $ và $ z'=a'+b'i $ khi đó $ z+z'=a+a'+(b+b')i $
\end{dang}

\subsubsection{A subsubsection}

\begin{dang*}
  Ta có $ z=a+bi $ và $ z'=a'+b'i $ khi đó $ z+z'=a+a'+(b+b')i $
\end{dang*}

\begin{dang*}[title=This is not in the table of contents]
  Ta có $ z=a+bi $ và $ z'=a'+b'i $ khi đó $ z+z'=a+a'+(b+b')i $
\end{dang*}

\end{document}

MWE output

| improve this answer | |

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.