3

I want to use \textcolor in the headings of my sections (see MWE below). My question differs to this question as I don't want to color all sections in one color (say red) and all subsections in another color (say green), but different sections in different colors.

\documentclass{beamer}
\usetheme{metropolis}
\begin{document}
\section{The \textcolor{red}{red} section}
\section{The \textcolor{green}{green} section}
\end{document}
Qaswed
  • 981

2 Answers2

6

To use the nice answer of @jfbu on overleaf, which uses some outdated packages, adding \protect before \textcolor seems to be necessary.

\documentclass{beamer}
\usetheme{moloch}% modern fork of the metropolis theme

\begin{document}

\section{The \protect\textcolor{red}{red} section} \begin{frame} A \end{frame}

\section{The \protect\textcolor{green}{green} section} \begin{frame} B \end{frame}

\end{document}

  • any idea why with no frames but the two sections there is error (on TL2018)? perhaps it is illegal to not have frames in beamer class? (but this may be theme dependent, it works ok without the metropolis theme) (but produces no output) (sorry if my ever extending comment looks confusing) –  Nov 15 '18 at 12:55
  • @jfbu Coincidently I just wrote a comment about this below your question :) – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:57
2

I have no problem with this. Your MWE was not compilable.

\documentclass{beamer}
\usetheme{metropolis}
\begin{document}
  \section{The \textcolor{red}{red} section}
\begin{frame}
A
\end{frame}
  \section{The \textcolor{green}{green} section}
\begin{frame}
B
\end{frame}
\end{document}

enter image description here

edited as per @samcarter request to move the \section outside the frames.

Notice that without the frame environment the example does not compile with an "arithmetic overflow" involving \calc@denominator.

There is at my local TL2108 no need for \protect with \textcolor in this use case, but @samcarter reports it is needed on overleaf. Please refer to her answer for more informed comments than mine.

  • I have to problems with the answer you gave. 1: it does not work on my "machine" (which is overleaf.com). What compiler (etc.) do you use? 2: it makes the sections as frames with a frame number which I would have to remove and resetting the counter. – Qaswed Nov 15 '18 at 11:47
  • @jfbu Can you please move all the sections outside of the frames? Otherwise this can lead to annoying side effects. – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:25
  • 1
    @Qaswed Overleaf seems to have some old package versions, but you can workaround with \section{The \protect\textcolor{red}{red} section} \begin{frame} (notice the \protect and that the section must be outside the frame) – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:28
  • @jfbu did you try without \protect on overleaf? – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:41
  • @samcarter no, but I am providing here answer for self-standing TeX installations, not for online services which can provide their own hotline. –  Nov 15 '18 at 12:44
  • @jfbu OK, then I'll add an answer for the special case of overleaf – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:45
  • @samcarter, yes +1 for doing that please. As per my answer I will remove what I said about \protect because yes, there is \protect\leavevmode but this can work only once. –  Nov 15 '18 at 12:50
  • @jfbu I think the calc error might be caused by all these progress bar things the metropolis theme provides, but not sure (and does not really matter anyway) – samcarter_is_at_topanswers.xyz Nov 15 '18 at 12:56
  • @samcarter thanks for that hint. Makes sense. –  Nov 15 '18 at 12:57
  • jfbu, thank you for your answer, and sorry, I did not point out more early that I'm using overleaf. Since FLonLon added this information to the question, I think picking the answer from samcarter is more correct. – Qaswed Nov 15 '18 at 13:38
  • @Qaswed yes, agreed. –  Nov 15 '18 at 13:43