在Beamer中使frametitle和block具有相同的寬度,嘗試2

在Beamer中使frametitle和block具有相同的寬度,嘗試2

在我的一些投影機主題我使用了答案在Beamer中使frametitle和block的寬度相同

然而現在一個問題已提出,這由以下 MWE 證明:

\documentclass{beamer}
\setbeamertemplate{block begin}{
    \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=0.2cm]{block title}%
    \usebeamerfont*{block title}%
        {\rule[-0.4ex]{0mm}{2ex}\insertblocktitle}%
            \end{beamercolorbox}%
    {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
    \usebeamerfont{block body}%
    \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=0.2cm]{block body}%
        \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}
\setbeamertemplate{block end}{
    \end{beamercolorbox}
    \vspace*{.25cm}
}
\setbeamertemplate{frametitle}{
\vspace*{0.3cm}
\begin{beamercolorbox}[wd=\textwidth, dp=0.3cm, ht=0.9cm, leftskip=0.2cm]{frametitle}
      \usebeamerfont{frametitle}\insertframetitle%
\end{beamercolorbox}
}
\setbeamercolor{block title}{bg=yellow}
\setbeamercolor{frametitle}{bg=yellow}

\begin{document}
\begin{frame}{Block}
This is text before the block.
\begin{block}{blocktitle} some text here 
\begin{itemize} 
\item This is an item in the block.
\end{itemize}
This is text after the itemize.
\end{block}
This is text after the block.
\end{frame}
\end{document}

在此輸入影像描述

正如您所看到的,區塊標題、區塊主體和周圍的文字都變得混亂且重疊。請幫我解決這個問題!同樣非常重要的是,包含框架標題的彩色框和包含區塊標題的彩色框(以及包含區塊主體的彩色框,如果有的話)保持相同的寬度。

答案1

我非常確信這段程式碼有問題,但它似乎確實解決了眼前的問題。連結的解決方案為區塊設定的固定高度等於為區塊和框架標題設定的高度。您不需要逐項來顯示問題 - 只需多行文字即可。

\documentclass{beamer}
\setbeamertemplate{block begin}{
  \vskip\baselineskip
  \begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=0.2cm]{block title}%
    \usebeamerfont*{block title}%
    {\rule[-0.4ex]{0mm}{2ex}\insertblocktitle}%
  \end{beamercolorbox}%
  {\nointerlineskip\vskip-0.5pt}%
  \usebeamerfont{block body}%
  \begin{beamercolorbox}[wd=\textwidth, leftskip=0.2cm]{block body}%
    \vskip-.75ex\vbox{}%
  }
  \setbeamertemplate{block end}{
  \end{beamercolorbox}
  \vspace*{.25cm}
}
\setbeamertemplate{frametitle}{
  \vspace*{0.3cm}
  \begin{beamercolorbox}[wd=\textwidth, dp=0.3cm, ht=0.9cm, leftskip=0.2cm]{frametitle}
    \usebeamerfont{frametitle}\insertframetitle%
  \end{beamercolorbox}
}
\setbeamercolor{block title}{bg=yellow}
\setbeamercolor{frametitle}{bg=yellow}

\begin{document}
  \begin{frame}{Block}
    This is text before the block.

    \begin{block}{blocktitle} some text here
      \begin{itemize}
        \item This is an item in the block.
      \end{itemize}
      This is text after the itemize.
    \end{block}
    This is text after the block.
  \end{frame}
\end{document}

給區塊內容一些喘息的空間

相關內容