我正在尝试用 LaTeX 定义自己的 beamer 包。我遇到了一个小问题,如果我的标题与第二行重叠,那么其余文本就会被向下推。
我希望能用 if 语句修复这个问题,但谷歌搜索没有找到任何有用的信息。我想说的是:
如果(标题与第二行重叠)则(从页面上方开始标题)
但我不确定如何用 LaTeX 来写它。
下面是一个工作示例...
这是 tex 文件:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\graphicspath{{Images/}}
\title{This is my short title that looks nice...}
\date[]{\today}
\author[My name]{My name \hfill \texttt{My email} \\[.5em] My affiliation}
\usetheme{mine}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Context}
Test frame
\end{frame}
\end{document}
这是 beamerinnertheme 文件,我在其中定义了 titlepage 并希望 if 语句为:
\mode<presentation>
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
% Top box.
\fill[color=green!20!black!90] (0,2) rectangle (\the\paperwidth, \the\paperheight);
% Left box.
\fill[color=green!20!black!90] (0,0) rectangle(2.95,1.9);
% Right box.
\fill[color=green!20!black!90] (3.05,0) rectangle(\the\paperwidth,1.9);
% Makes page white if not on page 1 (i.e. title page).
\ifnum\thepage>1\relax%
\fill[white,opacity=1] (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fi
\end{tikzpicture}
}
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
% Title page
\defbeamertemplate*{title page}{mine}[1][]
{
\vskip5.5cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{title page header}
\usebeamerfont{title}\inserttitle%
\end{beamercolorbox}%
\vskip0.25cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{date}
\usebeamerfont{author}\insertdate%
\end{beamercolorbox}
\vskip1.2cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{author}
\usebeamerfont{author}\insertauthor%
\end{beamercolorbox}
\vfill
}
答案1
您不必为此使用任何条件。只需将 放入 即可\inserttitle
。根据您的喜好\parbox[b][\f@size][b]{9cm}{\inserttitle}
更改其宽度\parbox
。
完整的主题文件变成:
\mode<presentation>
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
% Top box.
\fill[color=green!20!black!90] (0,2) rectangle (\the\paperwidth, \the\paperheight);
% Left box.
\fill[color=green!20!black!90] (0,0) rectangle(2.95,1.9);
% Right box.
\fill[color=green!20!black!90] (3.05,0) rectangle(\the\paperwidth,1.9);
% Makes page white if not on page 1 (i.e. title page).
\ifnum\thepage>1\relax%
\fill[white,opacity=1] (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fi
\end{tikzpicture}
}
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
% Title page
\defbeamertemplate*{title page}{mine}[1][]
{
\vskip5.5cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{title page header}
\usebeamerfont{title}\parbox[b][\f@size][b]{9cm}{\inserttitle}%
\end{beamercolorbox}%
\vskip0.25cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{date}
\usebeamerfont{author}\insertdate%
\end{beamercolorbox}
\vskip1.2cm%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{author}
\usebeamerfont{author}\insertauthor%
\end{beamercolorbox}
\vfill
}
下面显示了我的结果(抱歉字体是黑色——我的机器上找不到您使用的字体文件)。
答案2
正如另一个答案所述,使用\parbox
是首选解决方案。但是,如果您确实想使用条件(此处或模板中的其他地方),这并不难。您可以使用 存储一个盒子\savebox
,测量尺寸,然后添加所需的空间量。
梅威瑟:
\documentclass{beamer}
% one of the following
\title{This is my short title that looks nice...}
\title{This is the longer title that ruins the stuff below...}
\begin{document}
\begin{frame}
\setbeamercolor{coloredboxstuff}{fg=white,bg=green!20!black!90}
\newsavebox\mybox
\savebox\mybox{%
\begin{beamercolorbox}[wd=12cm,leftskip=3cm]{coloredboxstuff}%
\usebeamerfont{title}\inserttitle%
\end{beamercolorbox}%
}
\ifdim\ht\mybox>10pt\vskip2.5cm\else\vskip5.5cm\fi%
\usebox{\mybox}
\end{frame}
\end{document}
结果: