在以下 MWE 中,我设法将块标题和块主体重叠。但是,我想将块主体放在后面或将块标题放在前面。
\documentclass{beamer}
\usetheme{Dresden}
\setbeamercolor{block title}{fg=white,bg=blue}
\setbeamercolor{block body}{fg=black,bg=black!5}
\setbeamerfont{block title}{size=\normalsize,series=\bf}
\setbeamerfont{block body}{size=\normalsize}
\setbeamertemplate{block begin}{
\begin{beamercolorbox}[rounded=true]{block title}
\usebeamerfont*{block title}\insertblocktitle
\end{beamercolorbox}
\vskip-1pt
\usebeamerfont{block body}
\begin{beamercolorbox}[wd=1\linewidth,sep=1pt,leftskip=0.2cm,rightskip=0.2cm]{block body}\vskip1pt
}
\setbeamertemplate{block end}{
\vskip6pt
\end{beamercolorbox}
}
\begin{document}
\begin{frame}
\begin{block}{Title}
some text here
\end{block}
\end{frame}
\end{document}
答案1
与所有非标准块定制一样,答案是使用tcolorbox
:
\documentclass{beamer}
\usetheme{Dresden}
\usepackage[most]{tcolorbox}
\setbeamertemplate{block begin}{
\usebeamercolor[fg]{block body}
\usebeamercolor[fg]{block title}
\usebeamercolor[bg]{block body}
\usebeamercolor[bg]{block title}
\begin{tcolorbox}[
title=\parbox{\linewidth}{\insertblocktitle},
attach boxed title to top center={yshift=-2mm},
enhanced,
colback=structure.fg!75!black!10!,
colbacktitle=structure.fg!75!black,
frame empty,
]
}
\setbeamertemplate{block end}{
\end{tcolorbox}
}
\begin{document}
\begin{frame}
\begin{block}{Short title}
some text here
\end{block}
\begin{block}{A bit more long title}
some text here
\end{block}
\end{frame}
\end{document}
使用新的 tcolorbox 内部主题可以进一步简化代码 (https://www.ctan.org/pkg/beamertheme-tcolorbox):
\documentclass{beamer}
\usetheme{Dresden}
\usecolortheme{orchid}
\useinnertheme[rounded]{tcolorbox}
\tcbset{
minipage boxed title,
attach boxed title to top center={yshift=-1mm},
enhanced,
bottom=1mm,
}
\begin{document}
\begin{frame}
\begin{block}{Short title}
some text here
\end{block}
\begin{block}{A bit more long title}
some text here
\end{block}
\end{frame}
\end{document}