1

I am trying to create a simple colored box with tcbox in Beamer. Unfortunately, the following simple example does not work:

\documentclass[compress,aspectratio=169,12pt]{beamer}

\usepackage{tcolorbox}

\tcbset{colframe=blue!50!black,
  colback=white,
  colupper=red!50!black,
  fonttitle=\bfseries,center title}

\begin{document}

\begin{frame}{Questions}
  \tcbox{Hello\\ World}
\end{frame}

\end{document}

According to New line (line breaking) does not work for \tcbox, I could use [tikznode], and this really solves the problem.

Nevertheless, the documentation states that

% Fitted width box (like hbox or makebox)
\tcbox{Hello\\World!}

should work (page 14). Also,\begin{tcolorbox}Hello\\World!\end{tcolorbox} (also from page 14) works.

Is there some trick to get this working, e.g. using some special tcbset?

1 Answer 1

2

You could use the varwidth upper option:

\documentclass[compress,aspectratio=169,12pt]{beamer}

\usepackage{tcolorbox}
\usepackage{varwidth}

\tcbset{colframe=blue!50!black,
  colback=white,
  colupper=red!50!black,
  fonttitle=\bfseries,center title,
  varwidth upper}

\begin{document}

\begin{frame}{Questions}
  \tcbox{Hello\\ World}
\end{frame}

\end{document}

enter image description here

4
  • Thanks, this solves the problem! Could you maybe describe shortly what the reason for the problem is? This would help my understanding of why it happened and also possibly the understanding of future readers. Feb 11, 2023 at 12:02
  • 1
    @DavidGeorgReichelt I don't think there is a problem, that's juts how \tcbox works. The documentation shows that there won't be a line break i.stack.imgur.com/aaCoY.png and describes this box to work like a hbox. Feb 11, 2023 at 12:07
  • Thanks for the clarification. Still, my example produces ! LaTeX Error: Something's wrong--perhaps a missing \item. on pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) - shouldn't this just produce a colorbox without linebreak? Feb 11, 2023 at 12:30
  • @DavidGeorgReichelt It works in texlive2022. Feb 11, 2023 at 12:34

You must log in to answer this question.

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