[Tex/LaTex] No break line after theorem name in beamer

beamerline-breakingtheorems

I have applied the answer of question Theorem content right after theorem name in beamer to my question. I put \normalfont after \inserttheorempunctuation but the result is unexpected. Could you please see the image 1.

            \documentclass[envcountsect]{beamer}
            \usetheme{CambridgeUS}
            \usefonttheme{serif}
            \makeatletter
            \setbeamertemplate{theorem begin}
            {%
                \begin{\inserttheoremblockenv}
                    {%
                        \inserttheoremheadfont
                        \inserttheoremname
                        \inserttheoremnumber
                        \ifx \inserttheoremaddition \empty \else\ (\inserttheoremaddition)\fi%
                        \inserttheorempunctuation
                        \normalfont
                    }
                }
                \setbeamertemplate{theorem end}{\end{\inserttheoremblockenv}}
            \makeatother


             \begin{document}
                \section{ABC}
                \begin{frame}
                    \begin{theorem}[ABC]
                        This is a theorem
                    \end{theorem}
                \end{frame}
             \end{document}

The result is:

enter image description here

I would like to put the content right after Theorem (no break line). It looks like this

enter image description here

Best Answer

You need to put your formatting commands in to the body, rather than the title, of the theoremblockenv and select the block title font and colour for the heading elements to mimic the style you ask for. Compare with the two examples of blocks with and without titles.

Sample output

\documentclass[envcountsect]{beamer}

\usetheme{CambridgeUS}
\usefonttheme{serif}

\usepackage{etoolbox}

\makeatletter
\setbeamertemplate{theorem begin}
{%
\begin{\inserttheoremblockenv}
  {}{\usebeamerfont*{block title}\usebeamercolor[fg]{block title}%
  \inserttheoremname
  \inserttheoremnumber
  \ifx \inserttheoremaddition \empty \else\ (\inserttheoremaddition)\fi
  \inserttheorempunctuation}
  \normalfont
  }
  \setbeamertemplate{theorem end}{\end{\inserttheoremblockenv}}
\makeatother

\begin{document}

\section{ABC}

\begin{frame}

  \begin{theorem}[ABC]
    This is a theorem
  \end{theorem}

  Text.

  \begin{block}{Block title}
    A block with title.
  \end{block}

  Text.

  \begin{block}{}
    A block without title.
  \end{block}

\end{frame}

\end{document}