使用 tcolorbox 删除框上的空白

使用 tcolorbox 删除框上的空白

我正在尝试制作一个与文字大小相同的框,但我不知道该怎么做。我的代码:

\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}

我得到了这个结果:

在此处输入图片描述

但我想要这样的东西:

在此处输入图片描述

答案1

默认情况下,tcolorbox使用a\linewidth作为初始大小。据我所知,无法自动调整宽度以适应内容,但您可以使用widthtext width选项来减小框宽度。

以下代码显示了使用 的结果text width。在这种情况下,mybox声明了一个名为 的新 tcolorbox。这减少了输入。新的 tcolorbox 有一个强制参数(标题)和一个可选参数。在示例中,此可选参数用于引入对默认 的任何更改maybox,例如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}

在此处输入图片描述

答案2

在此处输入图片描述

\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}
\centering
        \begin{tcolorbox}[  enhanced, text width =3in,
            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;} }]{

                    \centering\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{tcolorbox}
        
        \begin{tcolorbox}[  enhanced,  text width=3in,
            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;
            } }]{
                
                    \centering\normalsize{
                        Felix Guillermo Gonzalez Hernandez
                    
                }
                
            }
        \end{tcolorbox}
        

\end{document}

相关内容