0

I'm trying to create a horizontal headline box consisting of two different colors. This is what I have right now:

\documentclass{beamer}
\usepackage{lmodern}


\definecolor{accent1}{RGB}{0, 110, 220} %blue
\definecolor{accent2}{RGB}{255, 248, 220} %cornsilk 

\setbeamercolor{accent12}{fg=accent1,bg=accent2}
\setbeamercolor{accent21}{fg=accent2,bg=accent1}

\setbeamerfont{section in head/foot}{family=\rm}

\makeatletter
\setbeamertemplate{headline}
{
    \leavevmode
    \hbox
    {
        \begin{beamercolorbox}[wd=0.5\paperwidth,ht=3ex,dp=1.5ex,right]{accent12}
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=0.5\paperwidth,ht=3ex,dp=1.5ex,left]{accent21}
            \usebeamerfont{section in head/foot}\hspace*{2ex}\insertsectionhead
        \end{beamercolorbox}

    }
    \vskip0pt%
}
\makeatother

\beamertemplatenavigationsymbolsempty %remove navigation panel

\begin{document}

\section{Introduction}
\begin{frame}
    hello
\end{frame}

\end{document}

example

there are a few problems with this code.

  1. As you can see in the output there is a small space between the two color boxes, but why? Both boxes are set to a width of 0.5\paperwidth?

  2. There are overfull hbox warnings, why and how to get rid of them?

LinG
  • 355
  • 2
    You have removed the % from my answer, that's what causes the small space. And the overfull hbox is logical for a line that's longer than 20.5\paperwidth. – TeXnician May 28 '17 at 10:56
  • @TeXnician I remember me taking this code a long time ago from your answer, but I also remember there were many %, which specific % are needed to get rid of the error? (Also, I never thought removing comment marks could make a code go from working to not working as intended...) – LinG May 28 '17 at 11:06
  • Those which were in there (between \makeatletter and \makeatother) are needed. What those do is essentially preventing TeX from inserting a space (at least that's the effect). – TeXnician May 28 '17 at 11:08
  • @TeXnician cool thanks, that works. I noticed that if I remove the hbox, I don't need the comment marks anymore... so is it only in the specific case that when one combines beamercolorboxes and hbox(\leavevmode and \hbox) or are there other things I should watch out for? – LinG May 28 '17 at 11:15
  • 1
    There are many cases you do actually need those comment marks, but you can read it up on this page (just search for it). Please have a look at that. – TeXnician May 28 '17 at 11:18

0 Answers0