0

I am in the process of creating a custom beamer theme, and in the beamerinnertheme.sty file I am trying to define the title, author, and date text boxes to automatically shrink their text to fit a pre-determined box size. From what I've found it looks like I'd use the tcolorbox package. I've defined the section where I want my box with

\newtcboxfit{\mybox}{width=\linewidth,colback=white,colframe=white} % Title page \defbeamertemplate*{title page}{texsx}[1][] { \vskip2.5cm% \begin{beamercolorbox}[wd=12cm,leftskip=1cm,sep=8pt,#1]{title goes here} \usebeamerfont{\mybox{title}\inserttitle}\par% \end{beamercolorbox}% \vskip0.75cm% \begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{author} \usebeamerfont{author}\insertauthor% \end{beamercolorbox} \vskip0.2cm% \begin{beamercolorbox}[wd=12cm,leftskip=3cm,#1]{date} \usebeamerfont{author}\insertdate% \end{beamercolorbox} \vfill } 

But this does not produce what I'm looking for, mostly being I can't make it so that the box defined takes the title input as an argument.

1 Answer 1

1

A couple of syntax problems:

  • The mandatory argument of the beamercolorbox environment has to be a beamer colour. Unless you have a custom defined colour names title goes here, I suspect you'd rather want something like \begin{beamercolorbox}[...]{title}

  • The \beamerfont macro needs as argument a beamer font, not your box, so it should be \usebeamerfont{title}

  • The argument of your box should be the text to be placed in the box, in your case this text is stored in \inserttitle, so you want to use \mybox{\inserttitle}

  • The fitting library of tcoolorbox needs to be given a height of the box. If you don't specify a height, it will assume a square box - given the aspect ratio of beamer frames you'd never see a shrinkage in this case.


\documentclass{beamer} \usepackage[most]{tcolorbox} \newtcboxfit{\mybox}{colback=red, colframe=red,width=\linewidth, height=1cm} % Title page \setbeamertemplate{title page}{ \vskip2.5cm% \begin{beamercolorbox}[wd=\linewidth,leftskip=0cm,sep=8pt]{title} \usebeamerfont{title}\mybox{\inserttitle}\par% \end{beamercolorbox}% \vskip0.75cm% \begin{beamercolorbox}[wd=\linewidth,leftskip=3cm]{author} \usebeamerfont{author}\insertauthor% \end{beamercolorbox} \vskip0.2cm% \begin{beamercolorbox}[wd=\linewidth,leftskip=3cm]{date} \usebeamerfont{author}\insertdate% \end{beamercolorbox} \vfill } \title{text very long text very long text text very long text very long text text very long text very long text} \author{names} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} 

enter image description here

(to prevent your theme from exploding, you might want to check if the fields you insert are actually filled or if they are empty...)

If you use a font which scales easily, e.g. which does not have different optical sizes, it might be easier to use the adjustbox package:

\documentclass{beamer} \setbeamerfont{title}{family=\fontfamily{LibertinusSans-LF}\selectfont}% just the first font I could think of which is missing optical sizes, not a recommendation to use this font \usepackage{adjustbox} \setbeamercolor{title}{bg=red} % Title page \setbeamertemplate{title page}{ \vskip2.5cm% \begin{beamercolorbox}[wd=\textwidth,leftskip=0cm,sep=8pt]{title} \usebeamerfont{title}\adjustbox{max width=\linewidth-16pt}{\inserttitle}\par% \end{beamercolorbox}% \vskip0.75cm% \begin{beamercolorbox}[wd=\linewidth,leftskip=3cm]{author} \usebeamerfont{author}\insertauthor% \end{beamercolorbox} \vskip0.2cm% \begin{beamercolorbox}[wd=\linewidth,leftskip=3cm]{date} \usebeamerfont{author}\insertdate% \end{beamercolorbox} \vfill } \title{text very long text very long text text very long text very long text text very long text very long text} \author{names} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} 

enter image description here

2
  • The issues I'm having with either of these proposed solutions is that the text starts shrinking once the max length of the textbox is reached. How do I have it continue to new lines, and only have it start shrinking once all lines are filled? Commented Feb 2, 2023 at 15:58
  • @DavidG. In the tcolorbox solution you set a suitable height. Commented Feb 2, 2023 at 16:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.