# How to wrap text in tcbtheorem

I think my problem might be really basic, but I went through the documentation and could not figure out how to force text to wrap inside a tcolorbox title, when the title is too long.

\documentclass[a4paper,11pt]{book}

\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}

\tcbset{
thmbox/.style={
enhanced,
breakable,
sharp corners=all,
fonttitle=\bfseries\normalsize,
fontupper=\normalsize\itshape,
top=0mm,
bottom=0mm,
right=0mm,
colback=white,
colframe=white,
colbacktitle=white,
coltitle=black,
attach boxed title to top left,
boxed title style={empty, size=minimal, bottom=1.5mm},
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--  ([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
},
}

\newtcbtheorem[number within=section]{questionbox}{Question}{thmbox}{qst}

\begin{document}

\begin{questionbox}{\lipsum[66]}{qst:1}
\lipsum[1]
\end{questionbox}
\end{document}

• At the moment your example does not even compile – user31729 Sep 12 '16 at 5:26
• Try \newrobustcmd{\mytitle}{\parbox[t]{0.7\textwidth}{\lipsum[1]}} to make a robust title box and use \mytitle instead of \lipsum[66] as title. The title in a theorem is just a \hbox which does neither wrap etc, unless using an inner parbox. It will not break like the real tcolorbox content. Just reduce your title -- that's the best option. – user31729 Sep 12 '16 at 5:40
• That's strange. I just copied the text into a new document and it compiled. Where in my code do I add \newrobustcmd{\mytitle}{\parbox[t]{0.7\textwidth}{\lipsum[1]‌​}} Wouldn't that print the same title every time? i.e. the contents of \lipsum[1]? I am still trying to figure out how things work. What I want to do, though, is to enter questions of variable size in the title (possibly up to 3 or 4 lines) and the answer in the body of the theorem box. I guess I'm trying to merge the theorem and the proof environments in the two boxes of tcolorbox, if that makes any sense – Mahoma Sep 12 '16 at 6:14
• @Mahoma You can use one box for both questions and answers. Questions are included in upper part and answers in lower. tcolorbox documentation shows several examples like these. Two special examples are shown in my answers to how-to-defer-content-to-a-later-part-of-the-document and hide-content-to-show-later where solutions are shown later on in your document. – Ignasi Sep 12 '16 at 7:41
• @Mahoma: Of course you must change the \mytitle box each time. But the two - box approach is the better one. – user31729 Sep 12 '16 at 13:12

As Christian explained, tcolorbox title is not wrapped. It's supposed to be some word and not a complete exercise. But if you want to mix questions and answers into the same color box, based on you format a possible solution could be to use a short title (or an empty one) and place the question in upper tcolorbox part while solution in placed in the lower part. Something like

\documentclass[a4paper,11pt]{book}

\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}

\tcbset{
thmbox/.style={
enhanced,
breakable,
sharp corners=all,
fonttitle=\bfseries\normalsize,
fontupper=\normalsize,
fontlower=\normalsize\itshape,
before lower={\itshape Solution:\ },
top=0mm,
bottom=0mm,
right=0mm,
colback=white,
colframe=white,
colbacktitle=white,
coltitle=black,
attach boxed title to top left,
boxed title style={empty, size=minimal, bottom=1.5mm},
overlay unbroken ={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
overlay first={
\draw (title.south west)--(title.south east);
\draw ([xshift=3.5mm]frame.north west)--  ([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay middle={
\draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
\draw (frame.north east)--(frame.south east);},
overlay last={
\draw ([xshift=3.5mm]frame.north west)|-%
(frame.south east)--(frame.north east);},
},
}

\newtcbtheorem[number within=section]{questionbox}{Question}{thmbox}{qst}

\begin{document}

\begin{questionbox}{A nice question}{qst:1}
\lipsum[1]
\tcblower
\lipsum[2]
\end{questionbox}
\end{document}

• I really like the solutions in your links! The only problem now is that when I print the list off tcbtheorems I no longer get the questions to be listed. I've been trying to figure out how to collect the contents of the tcolorbox rather than the title, since the question is no longer a title. I tried using this tex.stackexchange.com/questions/184764/… but I am not really understanding the options to adapt them to the colorbox – Mahoma Sep 13 '16 at 13:19
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7109511494636536, "perplexity": 3373.8664319172212}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-43/segments/1570986655735.13/warc/CC-MAIN-20191015005905-20191015033405-00528.warc.gz"}