1

I am trying to get an itemize environment to center in a tcolorbox automatically. A manual work-around is to put it inside a minipage and reduce the size of the minipage iteratively to the size of the itemize environment. I have looked for a minipage alternative like pbox but couldn't get it to work with that (but I'm not saying this is a dead-end, I have never used pbox before, so maybe just did something wrong). Any suggestions?

MWE:

\documentclass[tikz]{standalone}
\usepackage{tcolorbox}
\usepackage[]{enumitem}
\setlist[itemize]{leftmargin=*,nosep}

\newcommand{\boxwidth}{6.75cm}

\begin{document}
\begin{tikzpicture}
\node[](NAME) at (0,0)
{
    \begin{tcolorbox}[%
        title={\textcolor{white}{\textbf{The itemize env centered}}},
        width=\boxwidth, center title, center upper, colframe = red!50!black]
        \begin{minipage}{.77\textwidth} % HERE I don't want to adjust manually!
            \begin{itemize}
                \item bla bla 
                \item blub blub blub
                \item bliblalub-blaa blaba blubb
                \begin{itemize}
                    \item blubber die blub
                    \item lore em ipsum si
                \end{itemize}
            \end{itemize}
            \end{minipage}
    \end{tcolorbox}
};
\end{tikzpicture}
\end{document}

The MWE gives the result I want, however it requires manual adjustment of the width of the minipage. How to get this automated? I want the tcolorbox size to be fixed, because I am making a tree, where several tcolorboxes are used that should all have the same size, however the content in the itemize environments in the boxes will not always make full use of that space, thus, I'd like it to be centered in those cases...

2

A possible solution: Wrapping the itemize environment in another tcolorbox that is centered then. The left=... skipping might need some adjustment however.

\documentclass{standalone}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usepackage[]{enumitem}
\setlist[itemize]{leftmargin=*,nosep}

\newcommand{\boxwidth}{6.75cm}

\newtcolorbox{innerdummybox}[1][]{%
  enhanced,interior hidden,frame hidden,boxsep=0pt,top=0pt,right=0pt,#1}

\begin{document}



\begin{tcolorbox}[%
  title={\textcolor{white}{\textbf{The itemize env centered}}},
  width=\boxwidth, center title, colframe = red!50!black]
  \begin{innerdummybox}
    \begin{itemize}
    \item bla bla 
    \item blub blub blub
    \item bliblalub-blaa blaba blubb
      \begin{itemize}
      \item blubber die blub
      \item lore em ipsum si
      \end{itemize}
    \end{itemize}
    \end{innerdummybox}
\end{tcolorbox}

\end{document}

enter image description here

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.