我正在嘗試建立自訂標題頁,但無法編寫巨集來檢測日期欄位是否為空。如果是,block
則應簡單地繞過日期條目。
上圖看起來很奇怪,因為顯示了日期區塊標題,但實際日期為空。當然,我可以手動刪除這種情況下的日期區塊,但我仍然希望自動完成此操作。我還想知道如何確定某個欄位是否為空。
\documentclass[aspectratio=169, xcolor={x11names}]{beamer}
\usecolortheme{rose}
\setbeamercolor{itemize item}{fg=black}
\useoutertheme[]{tree}
\useinnertheme{inmargin}
\setbeamersize{text margin left=2mm, text margin right=2mm}
\newlength{\sidebarWidth}
\setlength{\sidebarWidth}{0.2\paperwidth}
\setbeamersize{sidebar width left=\sidebarWidth, sidebar width right=0cm}
\usefonttheme{structurebold}
\title{The Main Title of The Presentation}
\subtitle{Short Title Goes here}
\author{Al-Motasem Aldaoudeyeh}
\institute{North Dakota State University}
\date{}
\setbeamertemplate{headline}{}
\setbeamertemplate{date}{nothing}
\setbeamercolor{block title}{fg=blue}
\setbeamerfont{title page}{shape=\bfseries}
% Custome title page
\setbeamertemplate{title page}{
\vspace*{\stretch{3}}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\inserttitle
\end{block}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\large \insertsubtitle
\end{block}
\vspace{\stretch{2}}
\begin{block}{Author}
\insertauthor
\end{block}
\begin{block}{Institute}
\insertinstitute
\end{block}
\begin{block}{Date}
\insertdate
\end{block}
\vspace{\stretch{5}}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\end{document}
答案1
如果日期確實為空(例如,如果您的文件包含\date{}
),那麼您可以使用以下命令對此進行測試
\ifx\insertdate\empty%
\else%
\begin{block}{Date}
\insertdate
\end{block}
\fi
請注意,如果您的文件不包含任何\date
命令,則預設會顯示目前日期。
\documentclass[aspectratio=169, xcolor={x11names}]{beamer}
\usecolortheme{rose}
\setbeamercolor{itemize item}{fg=black}
\useoutertheme[]{tree}
\useinnertheme{inmargin}
\setbeamersize{text margin left=2mm, text margin right=2mm}
\newlength{\sidebarWidth}
\setlength{\sidebarWidth}{0.2\paperwidth}
\setbeamersize{sidebar width left=\sidebarWidth, sidebar width right=0cm}
\usefonttheme{structurebold}
\title{The Main Title of The Presentation}
\subtitle{Short Title Goes here}
\author{Al-Motasem Aldaoudeyeh}
\institute{North Dakota State University}
\date{}
\setbeamertemplate{headline}{}
\setbeamertemplate{date}{nothing}
\setbeamercolor{block title}{fg=blue}
\setbeamerfont{title page}{shape=\bfseries}
% Custome title page
\setbeamertemplate{title page}{
\vspace*{\stretch{3}}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\inserttitle
\end{block}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\large \insertsubtitle
\end{block}
\vspace{\stretch{2}}
\begin{block}{Author}
\insertauthor
\end{block}
\begin{block}{Institute}
\insertinstitute
\end{block}
\ifx\insertdate\empty%
\else%
\begin{block}{Date}
\insertdate
\end{block}
\fi
\vspace{\stretch{5}}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\end{document}
答案2
這是一個答案適用於空日期或“白色”日期
\documentclass[aspectratio=169, xcolor={x11names}]{beamer}
% Added code:
\makeatletter
\newcommand{\AddDateBox}{\xdef\mystring{\insertdate}\sbox1{\hbox{\mystring}}\sbox2{\hbox{\space}}\ifdim\wd1=\wd2\relax\else\ifx\insertdate\empty\relax\else\begin{block}{Date}\insertdate\end{block}\fi\fi}
\makeatother
\usecolortheme{rose}
\setbeamercolor{itemize item}{fg=black}
\useoutertheme[]{tree}
\useinnertheme{inmargin}
\setbeamersize{text margin left=2mm, text margin right=2mm}
\newlength{\sidebarWidth}
\setlength{\sidebarWidth}{0.2\paperwidth}
\setbeamersize{sidebar width left=\sidebarWidth, sidebar width right=0cm}
\usefonttheme{structurebold}
\title{The Main Title of The Presentation}
\subtitle{Short Title Goes here}
\author{Al-Motasem Aldaoudeyeh}
\institute{North Dakota State University}
\date{}
\setbeamertemplate{headline}{}
\setbeamertemplate{date}{nothing}
\setbeamercolor{block title}{fg=blue}
\setbeamerfont{title page}{shape=\bfseries}
% Custome title page
\setbeamertemplate{title page}{
\vspace*{\stretch{3}}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\inserttitle
\end{block}
\begin{block}{}
\usebeamercolor[fg]{title page}\usebeamerfont{block title}\usebeamertemplate{block title}
\large \insertsubtitle
\end{block}
\vspace{\stretch{2}}
\begin{block}{Author}
\insertauthor
\end{block}
\begin{block}{Institute}
\insertinstitute
\end{block}
\AddDateBox
\vspace{\stretch{5}}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\end{document}