1

I have a document similar to the following one:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}

\newtcolorbox{definition}[2][]{
    arc=5mm,
    lower separated=false,
    fonttitle=\bfseries,
    colbacktitle=green!10,
    coltitle=green!50!black,
    enhanced,
    attach boxed title to top left={xshift=0.5cm,
            yshift=-3mm},
    colframe=green!50!black,
    colback=green!10,
    title=#2}

\begin{document}
\begin{definition}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}
\blindtext
\end{definition}
\end{document}

A screenshot of the issue As you can see, the title is too long to be in one line. How would one create a line break inside of the boxed title here? I tried using \\, but it doesn't work.

2 Answers 2

1

As a work around, you can put the title in a \parbox of the relevant size:

\documentclass{article}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}

\newtcolorbox{definition}[2][]{
    arc=5mm,
    lower separated=false,
    fonttitle=\bfseries,
    colbacktitle=green!10,
    coltitle=green!50!black,
    enhanced,
    attach boxed title to top left={xshift=0.5cm,
            yshift=-3mm},
    colframe=green!50!black,
    colback=green!10,
    title=#2}

\begin{document}

\begin{definition}{\parbox{10.45cm}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}}
\blindtext
\end{definition}

\end{document} 

enter image description here

2

tcolorbox defines several solutions for long titles: minipage boxed title, varwidth boxed title, tikznode boxed title.

What follow is an example with the first one:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}

\newtcolorbox{definition}[2][]{
    arc=5mm,
    lower separated=false,
    fonttitle=\bfseries,
    colbacktitle=green!10,
    coltitle=green!50!black,
    enhanced,
    minipage boxed title*=-3cm,
    attach boxed title to top left={xshift=.5cm, yshift*=-\tcboxedtitleheight/2},
    colframe=green!50!black,
    colback=green!10,
    title=#2}

\begin{document}
\begin{definition}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}
\blindtext
\end{definition}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .