我不确定我想要的是否有可能实现,但问问也无妨……
我已调整itemize
环境,使项目文本与环境外的文本对齐。这可能看起来很奇怪,但由于我从未在同一张幻灯片上使用项目化和非项目化文本,所以这不是问题。
itemize
如果我在环境中使用,就会出现问题block
。在这种情况下,项目符号位于框的外面——这绝对不是我想要的。
我能否以某种方式区分itemize
块内的环境和块外的环境并进行\leftmargini
相应的设置?
\documentclass{beamer}
\usetheme{default}
\usecolortheme{crane}
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{0pt}}
\begin{document}
\begin{frame}
This is a text.
\begin{itemize}
\item This is an item.
\item This is another item
\begin{itemize}
\item with a subitem
\item and another subitem
\end{itemize}
\end{itemize}
\begin{alertblock}{Just A Block}
This is a text in a block.
\begin{itemize}
\item This is an item in a block.
\item Another item.
\end{itemize}
\end{alertblock}
\end{frame}
\end{document}
答案1
以下是否符合您的要求?我的解决方案重新定义了环境alertblock
,以便\leftmargini
在环境开始时将其重置为原始值;在 的alertblock
范围之外,\leftmargini
恢复为其全局值。当然,如果您愿意,您可以将该方法适应其他环境。
\documentclass{beamer}
\usetheme{default}
\usecolortheme{crane}
\newlength\origleftmargini
\setlength\origleftmargini\leftmargini
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{0pt}}
\let\oldalertblock\alertblock
\let\oldendalertblock\endalertblock
\def\alertblock{\begingroup \setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{\origleftmargini}} \oldalertblock}
\def\endalertblock{\oldendalertblock \endgroup}
\begin{document}
\begin{frame}
This is a text.
\begin{itemize}
\item This is an item.
\item This is another item
\begin{itemize}
\item with a subitem
\item and another subitem
\end{itemize}
\end{itemize}
\begin{alertblock}{Just A Block}
%\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{\origleftmargini}}
This is a text in a block.
\begin{itemize}
\item This is an item in a block.
\item Another item.
\end{itemize}
\end{alertblock}
\begin{itemize}
\item This is an item.
\item This is another item
\begin{itemize}
\item with a subitem
\item and another subitem
\end{itemize}
\end{itemize}
\end{frame}
\end{document}
答案2
您可以放置代码block alerted begin
来调整该块中包含的材料。在这种情况下,实现目标的一种方法是重新定义\@listi
。下面的定义是 beamer 的标准定义,只是将 的设置\leftmargin
更改\leftmargini
为3em
。根据需要调整此值。
\documentclass{beamer}
\usetheme{default}
\usecolortheme{crane}
\setbeamertemplate{itemize/enumerate body begin}{\setlength{\leftmargini}{0pt}}
\makeatletter
\addtobeamertemplate{block alerted begin}{
\def\@listi{\leftmargin3em
\topsep 3\p@ \@plus2\p@ \@minus2.5\p@
\parsep 0\p@
\itemsep3\p@ \@plus2\p@ \@minus3\p@}
}
\makeatother
\begin{document}
\begin{frame}
This is a text.
\begin{itemize}
\item This is an item.
\item This is another item
\begin{itemize}
\item with a subitem
\item and another subitem
\end{itemize}
\end{itemize}
\begin{alertblock}{Just A Block}
This is a text in a block.
\begin{itemize}
\item This is an item in a block.
\item Another item.
\end{itemize}
\end{alertblock}
\begin{itemize}
\item This is an item.
\item This is another item
\end{itemize}
\end{frame}
\end{document}
由于所涉及的代码使用包含@
它的内部变量,因此必须将其括在\makeatletter
/\makeatother
对中。