I have created a tcolorbox
(as given in tcolorbox
version 3.40 manual – page 155)
LaTeX Code:
\tcbset{
enhanced,
colback=red!5!white,
boxrule=0.1pt,
colframe=red!75!black,
fonttitle=\bfseries
}
My own shadow
\begin{tcolorbox}[title=My own shadow,
lifted shadow={1mm}{-2mm}{3mm}{0.1mm}%
{black!50!white}]
This is a tcolorbox.
\end{tcolorbox}
Current Output:
Expected Output (produced by explicitly setting: width=\linewidth/3):
My problem is:
This box contains only a little text, but occupies the whole textwidth
I have referred a related question here:
How to set fit height and width for tcbox according to the text inside?
but the options like: minimal
,tight
distort the box.
Is there any option through which this box can grow automatically in width depending on the width of the text contained in it?
Note: Adding \hbox solves this problem for normal text, but leads to a compilation error in case of bullet list.
Example:
\tcbset
{
enhanced,
left=8mm,
right=8mm,
boxrule=0.4pt,
colback=red!5!white,
boxrule=0.1pt,
colframe=red!75!black,fonttitle=\bfseries,
}
\begin{tcolorbox}[
title=\begin{center}Sample Title\end{center},
hbox,
lifted shadow={1mm}{-2mm}{3mm}{0.1mm}{black!50!white}
]
\begin{itemize}
\item First Line
\item Second Line
\end{itemize}
\end{tcolorbox}
Compilation Error: LaTeX Error: Something's wrong–perhaps a missing \item
Just for reference — The updated answer shows how to resolve this issue as well (using varwidth)
Best Answer
You can use
hbox
For revised question, you may need
varwidth
package to insert theitemize
. Also to center the title, use the optioncenter title
instead of\begin{center}
.