3

tcolorbox inside enumerate

I have a fancyvrb Verbatim environment inside a tcolorbox. When I use that tcolorbox as an item in an enumerate environment, the item number goes inside the tcolorbox. For example, the second item in the following code:

\documentclass[12pt]{article}
\usepackage{tcolorbox}
\usepackage{fancyvrb}

\newtcolorbox{codebox}[1]{
box align=top,
colback=white!5!white,
colframe=white!75!black,
title=#1
}

\begin{document}

\begin{enumerate}
  \item Lorem.
  \item
   \begin{codebox}{Swap}
      \begin{Verbatim}
   Hello. 
      \end{Verbatim}
    \end{codebox}
  \item Epsum.
\end{enumerate}

\end{document}

How can I bring the number out of the tcolorbox?

  • Welcome here yang5! – cfr Sep 25 '16 at 1:44
3

Do you want something like this?

more-or-less-aligned box

\documentclass[12pt]{article}
\usepackage{tcolorbox}
\usepackage{fancyvrb}

\newtcolorbox{codebox}[1]{
  colback=white!5!white,
  colframe=white!75!black,
  title=#1,
  box align=top,
  before skip=-\baselineskip
}

\begin{document}

\begin{enumerate}
  \item Lorem.
  \item \mbox{}
  \begin{codebox}{Swap}
    \begin{Verbatim}
   Hello.
   \end{Verbatim}
  \end{codebox}
  \item Epsum.
\end{enumerate}

\end{document}

I'm sure tcolorbox must have an option for aligning to the title somewhere (or using T alignment`) as it has options for everything else. But I couldn't see anything obvious ....

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.