Tcolorbox – How to Remove White Space on a Box Using Tcolorbox

tcolorbox

I'm trying to make a box with the same size as the writing, but i don't know how. My code:

\documentclass[A4paper, twoside, 11pt]{article}
\usepackage[top=2.5 cm, bottom=3.8 cm, left=2 cm, right=2 cm]{geometry}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{hyperref}
\hypersetup{colorlinks=true,
    linkcolor=blue,             
    urlcolor=blue,
    citecolor=cyan}
\urlstyle{same}


\begin{document}
\begin{center}
\begin{tcolorbox}[  enhanced,
                    title=\normalsize{Equipe},
                    breakable,
                    colframe=blue!50!black,
                    colback=white,
                    colbacktitle=blue!5!white,
                    fonttitle=\bfseries,
                    coltitle=black,
                    attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,
                    yshifttext=2mm-\tcboxedtitleheight/2},
                    boxed title style={boxrule=0.5mm,
                    frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
                    -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
                    -- (frame.south east) -- (frame.south west) -- cycle; },
                    interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
                    -- (interior.north west) -- (interior.north east)
                    -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
                    -- cycle;} }]{
                \begin{center}
                \normalsize{
                    Felipe Gimenez Souza - 11916728\footnote{E-mail: \href{mailto: [email protected]}{[email protected]}}
            
                   \vspace{0.2cm}
            
                    Matheus Fogaça Cichocki - 11809990\footnote{E-mail: \href{mailto: [email protected] } {[email protected]}}
            
                   \vspace{0.2cm}
            
                    Lucas Roda Ximenes dos Santos - 11917239\footnote{E-mail: \href{mailto:  [email protected]}{[email protected]}}}
                \end{center}
                }
        \end{tcolorbox}

\begin{tcolorbox}[  enhanced,
                    title=\normalsize{Professor},
                    breakable,
                    colframe=blue!50!black,
                    colback=white,
                    colbacktitle=blue!5!white,
                    fonttitle=\bfseries,
                    coltitle=black,
                    attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,
                    yshifttext=2mm-\tcboxedtitleheight/2},
                    boxed title style={boxrule=0.5mm,
                    frame code={ 
                        \path[tcb fill frame] ([xshift=-4mm]frame.west)
                        -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
                        -- (frame.south east) -- (frame.south west) -- cycle; 
                    },
                    interior code={ 
                        \path[tcb fill interior] ([xshift=-2mm]interior.west)
                        -- (interior.north west) -- (interior.north east)
                        -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
                        -- cycle;
                        } }]{
                \begin{center}
                \normalsize{
                    Felix Guillermo Gonzalez Hernandez
                    }
                \end{center}
                }
        \end{tcolorbox}

\end{center}
\end{document}

And i obtain this result:

enter image description here

But i want something like that:

enter image description here

Best Answer

By default, a tcolorbox uses \linewidth as initial size. To my knowledge is not possible to automatically adjust the width to the contents, but you can use width and text width options to reduce box width.

Following code shows the result with text width. In this case a new tcolorbox called mybox is declared. This reduces typing. The new tcolorbox has one mandatory parameter, the title, and an optional one. In the example this optional parameter is used to introduce any change to the default maybox, like text width.

\documentclass[A4paper, twoside, 11pt]{article}
\usepackage[top=2.5 cm, bottom=3.8 cm, left=2 cm, right=2 cm]{geometry}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{hyperref}
\hypersetup{colorlinks=true,
    linkcolor=blue,             
    urlcolor=blue,
    citecolor=cyan}
\urlstyle{same}

\newtcolorbox{mybox}[2][]{%
    enhanced,
    title=\normalsize{#2},
    breakable,
    colframe=blue!50!black,
    colback=white,
    colbacktitle=blue!5!white,
    fonttitle=\bfseries,
    coltitle=black,
    attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,
                    yshifttext=2mm-\tcboxedtitleheight/2},
    boxed title style={boxrule=0.5mm,
        frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
                    -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
                    -- (frame.south east) -- (frame.south west) -- cycle; },
        interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
                    -- (interior.north west) -- (interior.north east)
                    -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
                    -- cycle;} 
    },
    halign=center,
    center,
    #1
}

\begin{document}
\begin{mybox}[text width=8cm]{Equipe}
                    Felipe Gimenez Souza - 11916728\footnote{E-mail: \href{mailto: [email protected]}{[email protected]}}
            
                   \vspace{0.2cm}
            
                    Matheus Fogaça Cichocki - 11809990\footnote{E-mail: \href{mailto: [email protected] } {[email protected]}}
            
                   \vspace{0.2cm}
            
                    Lucas Roda Ximenes dos Santos - 11917239\footnote{E-mail: \href{mailto:  [email protected]}{[email protected]}}
\end{mybox}

\begin{mybox}{Professor}
                    Felix Guillermo Gonzalez Hernandez
\end{mybox}

\end{document}

enter image description here