2

I'm attempting to define my own beamer package in LaTeX. I've run into a small problem whereby if my title overlaps onto a second line then the rest of the text is pushed downwards.

I was hoping I could fix this with an if statement but Googling hasn't resulted in anything too helpful. I would like to say something along the lines of:

if (title overlaps onto second line) then (start title higher up the page)

But I'm not sure how to write that in LaTeX.

Below is a working example...

This is the tex file:

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

and this is the beamerinnertheme file in which I define the titlepage and would like the if statement to be:

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

This is an example that looks nice... enter image description here

And this is one that doesn't work... enter image description here

1

2 Answers 2

2

You don't have to use any conditional for that. Just put the \inserttitle into a \parbox[b][\f@size][b]{9cm}{\inserttitle}. Change the width of that \parbox to your liking.

The complete theme-file becomes:

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

The following shows my results (sorry for black font -- the font file you use wasn't found on my machine).

enter image description here

1

As the other answer states, using \parbox is the preferred solution. However, if you do want to use conditionals (here or elsewhere in the template), it is not very difficult. You can store a box using \savebox, measure the size, and add the required amount of space.

MWE:

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

Result:

enter image description here

1
  • As an addition, one could also add space based on the box space (not conditional but calculated) with something like: \vskip0.5\ht\mybox or even \vskip\dimexpr0.5\ht\mybox-1in\relax.
    – Skillmon
    Commented Aug 22, 2017 at 11:10

Not the answer you're looking for? Browse other questions tagged .