1

I am trying to create a custom title page but I am not able to write a macro that detects whether the date field is empty or not. If it is then the block of the date entry should simply be bypassed.

enter image description here

The image above looks weird since the date block title is shown but the actual date is empty. Of course I can manually remove the date block for such case, but I still want this to be done automatically. I also want to know how to determine if some field is empty or not.

\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}
0

If the date is truly empty (e.g. if your document contains \date{}), then you can test for this with

\ifx\insertdate\empty%
\else%
   \begin{block}{Date}
       \insertdate
   \end{block}   
\fi

Note that if your document does not contain any \date command, the current date wil be shown by default.

\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}

enter image description here

0

Here is an answer that works for empty or "white" date

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.