![Itemize 环境的自动宽度框](https://linux22.com/image/410417/Itemize%20%E7%8E%AF%E5%A2%83%E7%9A%84%E8%87%AA%E5%8A%A8%E5%AE%BD%E5%BA%A6%E6%A1%86.png)
使用 varwidth 和 tikz 定义一个 newenvironment,以获取宽度等于其中内容的块。除非涉及分项,否则它可以正常工作。这里给出了 MWE。
\documentclass[]{beamer}
\usepackage{tikz}
\usepackage{varwidth}
\tikzstyle{example-box} = [fill=yellow, rectangle]
\newenvironment{autowidthblock}{
\begin{tikzpicture}
\node [example-box] (box)
\bgroup
\begin{varwidth}{\linewidth}
}{
\end{varwidth}
\egroup;
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\begin{autowidthblock}
With normal sentences, the width is rightly fit
\end{autowidthblock}
\begin{autowidthblock}
\begin{itemize}
\item With itemize environment,
\item The width is not auto-set
\item Instead spans the entire textwidth
\end{itemize}
\end{autowidthblock}
\end{frame}
\end{document}