0

I am dealing with tcolorbox and it was working great until my title exceeded one line width. The problem is that text doesn't wrap to a new line.

Compared to a box with normal text width it looks like this:

enter image description here

I supply title together with other variables like this:

\begin{tcolorbox}[title=...]
...
\end{tcolorbox}

I read in documentation on CTAN (ch. 4.1 on p. 18) that there are some alternatives to title. Those alternatives are adjusted title, squeezed title and squeezed title* but none of those offer multiline support.

Does anyone have an solution?

I probably won't use mdframed package again, because it produced error tex capacity exceeded multiple times while I was in the middle of a large project and it was a pain to swap it for tcolorbox...


This is the minimal working example as requested:

\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[slovene]{babel}

\usepackage{units}
\usepackage{acronym}
\usepackage{hyperref}
\usepackage{multicol}

\usepackage{xcolor}
\usepackage{color}

\hypersetup{
    colorlinks=true
}

\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\newcommand{\vprasanje}[4]{
\begin{tcolorbox}[%
breakable,%
left=5mm,%
right=5mm,%
top=5mm,%
bottom=5mm,%
toptitle=0mm,%
bottomtitle=0mm,%
lefttitle=0mm,%
righttitle=0mm,%
boxrule=0.15mm,%
arc=0.25mm,%
colback=red!20!white,%
colframe=red!80!white,%
fonttitle=\hypersetup{allcolors=white!10!white},%
title={\underline{\makebox[\textwidth]{\textit{"{#2}"}\hfill}}}\newline{\makebox[\textwidth]{\hfill{\scriptsize \uppercase{\textbf{Viri}}:~~\textit{#3}}}}%
]
#4
\end{tcolorbox}
}

\begin{document}

\vprasanje{1}{This is the longlonglong longlonglong longlong longlong longlong longlong longlong longlong long longlong long long long long long long long long long long long long long long long long long long long question.}{some references}{This is the long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long answer.}

\end{document}
  • 1
    If you try the example provided by documentation (section 4.1, p. 18) with a long title, tcolorbox uses two or more lines... Can you give a MWE? – Paul Gaborit Dec 30 '16 at 8:52
  • I provided the MWE and I think that anomaly is provided with \makebox... Is it posible to have multiline makebox? – 71GA Dec 30 '16 at 9:22
  • 1
    Ok I found the solution by using \parbox{}{} instead of \makebox[]{}. It looks like I missdiagnosed the problem... – 71GA Dec 30 '16 at 9:27
  • @71GA you can post your solution as an answer for future reference :) – Yorgos Dec 30 '16 at 9:30
2

The main cause for the problem is that \underline does not wrap the text inside its argument, but \uline from ulem package does, under certain conditions.

There is no need of using outer \parbox etc. environments here, in my point of view.

However, underlining should be not used (too much)

\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[slovene]{babel}
\usepackage{ulem}

\usepackage{units}
\usepackage{acronym}
\usepackage{hyperref}
\usepackage{multicol}

\usepackage{xcolor}
\usepackage{color}

\hypersetup{
    colorlinks=true
}

\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\newcommand{\vprasanje}[4]{
  \begin{tcolorbox}[%
    breakable,%
    left=5mm,%
    right=5mm,%
    top=5mm,%
    bottom=5mm,%
    toptitle=0mm,%
    bottomtitle=0mm,%
    lefttitle=0mm,%
    righttitle=0mm,%
    boxrule=0.15mm,%
    arc=0.25mm,%
    colback=red!20!white,%
    colframe=red!80!white,%
    fonttitle=\hypersetup{allcolors=white!10!white},%
    title={{\itshape\uline{"#2"}}
      \vskip0.1ex
      \hfill\scriptsize \uppercase{\textbf{Viri}}:~~\textit{#3}}%
]
#4
\end{tcolorbox}
}

\begin{document}

\vprasanje{1}{This is the longlonglong longlonglong longlong longlong longlong longlong longlong longlong long longlong long long long long long long long long long long long long long long long long long long long question.}{some references}{This is the long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long answer.}

\end{document}

enter image description here

1

I found the solution by using \parbox{}{} instead of \makebox[]{}. It looks like I misdiagnosed the problem...

  • 1
    Congratulations. Could you please add the correct backticks around your code-snippets "`" and maybe could you also post the corrected MWE or at least the changed line in complete. Also: mark your questions as solved. (I have to edit more than 6 char, hence I was not allowed to change the ticks for you.) – Jan Dec 30 '16 at 9:59

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.