我正在为 beamer 模板编写代码。我有两个不同的模板frametitle
,其中一个使框架有点不对称。因此,我将text margin left
和分别设置text margin right
为8ex
和5ex
。另一个更对称,因此我希望之后\setbeamertemplate{frametitle}[second template]
所有框架中的文本都居中。
当然我不能\setbeamersize
在文档正文中使用。使用\newgeometry
会移动整个框架。我不知道如何adjustwidth
为所有框架设置。
这是 MWE
\documentclass[aspectratio=169]{beamer}
\usepackage[english]{babel}
\setbeamercolor{frametitle}{fg=white, bg=blue!20!black}
\defbeamertemplate{frametitle}{plain}{%
\nointerlineskip%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{frametitle}%%
\insertframetitle%
\end{beamercolorbox}%
}
\makeatletter
\defbeamertemplate{frametitle}{leftside}{%
\nointerlineskip%
\hspace{\dimexpr-\beamer@leftmargin - 1cm\relax}%
\begin{beamercolorbox}[%
wd=1cm,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{example text}%
\vphantom{F}
\end{beamercolorbox}%
\smash{%
\rotatebox[origin=rt]{90}{%
\begin{beamercolorbox}[%
wd=\paperheight,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{frametitle}%
\insertframetitle
\end{beamercolorbox}%
}%
}%
\vskip-3ex
}
\makeatother
\setbeamersize{text margin left=8ex, text margin right=3ex}
\begin{document}
\setbeamertemplate{frametitle}[leftside]
\begin{frame}{Frame Title}
The text here is placed correctly\hfill the right margin is ok
\end{frame}
\setbeamertemplate{frametitle}[plain]
\begin{frame}{Frame Title}
The text here is not ok \hfill too close to the right margin\\
\hspace{-2.5ex}Here it is ok\hfill and the right margin is also ok\hspace{2.5ex}
\end{frame}
\end{document}
更新
我在序言中添加了以下代码
\usepackage{changepage}
\newlength{\leftshift}
\setlength{\leftshift}{-1.5ex}
\makeatletter
\pretocmd\endbeamer@frameslide
{\end{adjustwidth}}
{}
{}
\apptocmd\beamer@frameslide
{\begin{adjustwidth}{\leftshift}{-\leftshift}}
{}
{}
\makeatother
\leftshift
每次加载新模板时都会更改。它工作得很好,尽管内联frametitle
被读取为框架的文本(我的意思是\begin{frame}{This text is read inside text area}
。如果有人能修复它我会很高兴。
答案1
如果您的文本宽度保持不变,并且您不需要导航符号或其他静态元素,则可以通过更改以下内容来解决\hoffset
:
\documentclass[aspectratio=169]{beamer}
\usepackage[english]{babel}
\setbeamertemplate{navigation symbols}{}
\setbeamercolor{frametitle}{fg=white, bg=blue!20!black}
\makeatletter
\defbeamertemplate{frametitle}{plain}{%
\nointerlineskip%
\hspace*{2.3ex}%
\begin{beamercolorbox}[%
wd=\paperwidth,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{frametitle}%%
\insertframetitle%
\end{beamercolorbox}%
}[action]{
\hoffset=-3ex
}
\defbeamertemplate{frametitle}{leftside}{%
\nointerlineskip%
\hspace{\dimexpr-\beamer@leftmargin - 1cm\relax}%
\begin{beamercolorbox}[%
wd=1cm,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{example text}%
\vphantom{F}
\end{beamercolorbox}%
\smash{%
\rotatebox[origin=rt]{90}{%
\begin{beamercolorbox}[%
wd=\paperheight,%
sep=2ex,%
leftskip=.2ex,%
rightskip=.2ex,%
]{frametitle}%
\insertframetitle
\end{beamercolorbox}%
}%
}%
\vskip-3ex
}[action]{
\hoffset=0ex
}
\makeatother
\setbeamersize{text margin left=8ex, text margin right=3ex}
\begin{document}
\setbeamertemplate{frametitle}[leftside]
\begin{frame}
\frametitle{Frame Title}
The text here is placed correctly\hfill the right margin is ok
\end{frame}
\setbeamertemplate{frametitle}[plain]
\begin{frame}
\frametitle{Frame Title}
The text here is not ok \hfill too close to the right margin
\end{frame}
\begin{frame}
\frametitle{Frame Title}
The text here is not ok \hfill too close to the right margin
\end{frame}
\setbeamertemplate{frametitle}[leftside]
\begin{frame}
\frametitle{Frame Title}
The text here is placed correctly\hfill the right margin is ok
\end{frame}
\end{document}