[Tex/LaTex] Behaviour of frametitle with raisebox

beamerraise

See update below.
The following problem occurred while I was trying to alter the frametitle in beamer. (Actually I want a picture in the Titlebar. I used a rule instead.)

\documentclass{beamer}
\usetheme{AnnArbor}  

\setbeamercolor*{frametitle in title}{fg=red, bg=black}

\setbeamertemplate{frametitle}{%
    \vspace{-0.165ex}
    \mbox{%
        \begin{beamercolorbox}[wd=\paperwidth, dp=1ex, ht=4.5ex, sep=1ex, colsep*=0pt]{frametitle in title}%
        \usebeamerfont{frametitle}
        \insertframetitle 
        \hfill
        \raisebox{-1.75ex}[\ht\strutbox][-\ht\strutbox]{\rule{5ex}{5ex}}
        \end{beamercolorbox}%
        }%
    }

\begin{document}

\begin{frame}
\frametitle{Hello}
Everythings fine here
\end{frame}

\begin{frame}%[fragile]
\frametitle{Can you see?} 
DO
\end{frame}

\end{document}

So you can easily see that the red square representing the picture (I want it there) is shifted upwards on a fragile frame. I have no idea how fragile works (neither I have an idea about beamer but I was able to handle it so far.) Therefore I thought about an if-construct to figure out when fragil is on but… well there is no such construct available in user land…

thx for comments!

Update:
I just figured out, that the Problem has nothing to do with fragiles frames.
It comes from letters with descender. So in fact I'm struggling to use \raisebox correctly.

Best Answer

You are quite right, the problem comes from the descender of the "y" in "Can you see". (It's quite natural that you were puzzled and first thought fragile to be the culprit; I had a related question where I also didn't know what's happening. Juan A. Navarro called it "the dreadful Beamer's vertical alignment problem" ...)

Solution: Add a \strut to your frame titles, like this:

\frametitle{Hello\strut}
\frametitle{Can you see?\strut}

Then you see that the picture isn't shifted anymore. Now the picture is too high, but this can easily be solved by adapting the \raisebox{-1.75ex} of the picture.

Related Question