1

I'm trying to use tcolorbox to highlight list items in an enumerate environment with the label inside the box and aligned with any list item labels that occur previously. However, I can't get the enumeration labels to be inside the tcolorbox.

Here is the code showing the labels outside of the tcolorbox.

Any help would be greatly appreciated.

    \documentclass{article}
    \usepackage{tcolorbox, enumitem}

    \newtcolorbox{mybox}[1]{
     halign title=center,
     squeezed title*={\rmfamily\textsc{\textbf{#1}}},
                arc=0mm,%
                colbacktitle=blue,%
                colback=blue!5!white,%
                colframe=blue,%
                left=0mm,%
                right=0mm,%
                top=0.5mm,%
                bottom=0.5mm,%0.3mm
                boxsep=0mm,%
                boxrule=0.1mm,%
                nobeforeafter,%
                width=\linewidth,%
                box align=center,%
    }

    \begin{document}
    \section{Testing}
    \begin{enumerate}
    \item entry 1
    \item entry 2
    %Blank item, and tcolorbox shifted to the left with enumitem widths
    \item[]\hspace{-\labelwidth}\hspace{-\labelsep}\begin{mybox}{Title}
    % enumerations inside box
    \item box entry
    \item box entry 2
  \end{mybox}
  %continued list outside of the box
  \item final entry
  \end{enumerate}
  \end{document}

Current code

5
  • 1
    Is this the expected output? i.stack.imgur.com/4t60Z.png
    – leandriis
    Apr 18, 2021 at 21:19
  • When I compile this, I have an enumerated list with "entry 1" and "entry 2", then a tcolorbox showing "box entries" labelled 3 and 4 respectively, but with the item labels outside the box. This is followed "final entry" continuing in a standard enumeration, labelled as entry 5. My goal is to get the labels for 3 and 4 inside the box, but inline with the labels 1, 2, and 5.
    – Steve
    Apr 18, 2021 at 22:06
  • @leandriis I apologize, I just saw your image link now. Yes, the image you posted is exactly what I'm looking for. I have edited my original post and attached an image of what I am able to get.
    – Steve
    Apr 19, 2021 at 4:16
  • @Steve What is the utility of this?
    – projetmbc
    Apr 19, 2021 at 7:20
  • @projetmbc I'm writing instructional info and I'm using this to highlight specific steps within a list, the title giving specific info on what the purpose of this step is. I've had it working enough to get the formatting, but LaTeX throws errors about it getting lost or missing items, etc... I've been trying to eliminate that on my own for some time. I appreciate the simple solution.
    – Steve
    Apr 19, 2021 at 16:53

1 Answer 1

0

enter image description here

I ended the list right before the box, started and ended a new enumerate inside of tcolorbox, and used a third enumerate environment after the box. In order to get consecutive numbering across all three lists, I used series and resume.

\documentclass{article}
\usepackage{tcolorbox, enumitem}

\newtcolorbox{mybox}[1]{
 halign title=center,
 squeezed title*={\rmfamily\textsc{\textbf{#1}}},
            arc=0mm,%
            colbacktitle=blue,%
            colback=blue!5!white,%
            colframe=blue,%
            left=0mm,%
            right=0mm,%
            top=0.5mm,%
            bottom=0.5mm,%0.3mm
            boxsep=0mm,%
            boxrule=0.1mm,%
            nobeforeafter,%
            width=\linewidth,%
            box align=center,%
}

\begin{document}
\section{Testing}
  \begin{enumerate}[series=myenumerate]
    \item entry 1
    \item entry 2
  \end{enumerate}
\begin{mybox}{Title}
  \begin{enumerate}[resume=myenumerate]
    \item box entry
    \item box entry 2
  \end{enumerate}
\end{mybox}
  \begin{enumerate}[resume=myenumerate]
    \item final entry
  \end{enumerate}
\end{document}

You must log in to answer this question.

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