自动调整 beamer 中的标题图像 (beamerinnertheme.sty)

自动调整 beamer 中的标题图像 (beamerinnertheme.sty)

我正在尝试创建自己的 Beamer 主题,但在一些可能很简单的事情上失败了。不幸的是,我根本搞不懂,希望有人能为我提供解决方案。从标题中可以看出,这是关于我想要自己创建的 Beamer 主题的封面图片。

在 beamerinnertheme.sty 中,我已经在社区的帮助下指定,如果未选择标题图像,则采用默认图像。

但现在我想添加代码或选择在 presentation.tex 文件中选择一个标题图像,该图像会自动适应框架,当然也会适应所选的纵横比。

换句话说,在 presentation.tex 中,例如,命令:

\titlepicture{file}

它会通过 innertheme 自动出现在正确的位置。

\documentclass[10pt,%
aspectratio=1609,%
]{beamer}

\usepackage {mwe}
\usepackage{tikz}
\usepackage{xcolor}

\title{TITLE}
\author{NAME}
\institute{INSTITUT}
\date{DATE}
%\titlegraphic{example-image-a}

%beamertheme.sty
\setbeamertemplate{navigation symbols}{}

%beamercolortheme.sty
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{structure}{fg=white}
\setbeamercolor*{section in toc}{fg=gray}
\setbeamercolor*{framtitle}{fg=white}
\setbeamercolor*{section}{fg=white}
\setbeamercolor*{normal text}{fg=gray}
\setbeamercolor*{foot}{fg=gray,bg=white}
\setbeamercolor*{title}{fg=white}
\setbeamercolor*{title page header}{fg=white}

%beamerinnertheme.sty
\defbeamertemplate*{title page}{test}[1][]
{
   \begin{tikzpicture}[remember picture,overlay]
       \node[fill=blue,minimum height=1cm,text width=\paperwidth] at ([yshift=2.5cm]current page.south) {\hspace{4cm}\usebeamerfont{title}\inserttitle};
       \fill[color=green] (current page.south west) rectangle ++(2.95,1.9);
       \node[fill=red,minimum height=1.9cm,text width=\paperwidth-6.5cm] at ([yshift=0.95cm]current page.south) {\hspace{0.9cm}\usebeamerfont{author}\insertauthor\par\vskip0.1cm \hspace{0.9cm}\usebeamerfont{author}\insertdate};
       \node[anchor=south east, inner sep =0.1cm] at (current page.south east) {\includegraphics[width=2.8cm]{example-image-b}};
       \ifx\inserttitlegraphic\empty%
       \node[anchor=south, inner sep=0cm] at ([yshift=3cm]current page.south) {\includegraphics[width=\paperwidth]{example-image-16x9}};
       \fi     
   \end{tikzpicture}   
}

\begin{document}
   \begin{frame}[plain]
       \titlepage
   \end{frame}
   \section{Sec 1}
   \begin{frame}{Title}
       \blindtext
   \end{frame}
   \section{Sec 2}
   \begin{frame}{Title 2}
       \framesubtitle{Subtitle}
       \blindtext
   \end{frame}

\end{document}

答案1

您已经在\ifx\inserttitlegraphic\empty测试用户是否设置了\titlegraphic宏。您可以使用此测试的 else 分支将默认图像替换为用户选择的图像。

我不会自动调整宽高比。在几乎所有情况下,这都会扭曲图像。让用户决定他们想要的图像有多大。

\documentclass[10pt,%
aspectratio=1609,%
]{beamer}

\usepackage{mwe}
\usepackage{tikz}
%\usepackage{xcolor}

\title{TITLE}
\author{NAME}
\institute{INSTITUT}
\date{DATE}
\titlegraphic{\includegraphics[width=\paperwidth]{example-image-duck}}

%beamertheme.sty
\setbeamertemplate{navigation symbols}{}

%beamercolortheme.sty
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{structure}{fg=white}
\setbeamercolor*{section in toc}{fg=gray}
\setbeamercolor*{framtitle}{fg=white}
\setbeamercolor*{section}{fg=white}
\setbeamercolor*{normal text}{fg=gray}
\setbeamercolor*{foot}{fg=gray,bg=white}
\setbeamercolor*{title}{fg=white}
\setbeamercolor*{title page header}{fg=white}

%beamerinnertheme.sty
\defbeamertemplate*{title page}{test}[1][]
{
   \begin{tikzpicture}[remember picture,overlay]
       \node[fill=blue,minimum height=1cm,text width=\paperwidth] at ([yshift=2.5cm]current page.south) {\hspace{4cm}\usebeamerfont{title}\inserttitle};
       \fill[color=green] (current page.south west) rectangle ++(2.95,1.9);
       \node[fill=red,minimum height=1.9cm,text width=\paperwidth-6.5cm] at ([yshift=0.95cm]current page.south) {\hspace{0.9cm}\usebeamerfont{author}\insertauthor\par\vskip0.1cm \hspace{0.9cm}\usebeamerfont{author}\insertdate};
       \node[anchor=south east, inner sep =0.1cm] at (current page.south east) {\includegraphics[width=2.8cm]{example-image-b}};
       \ifx\inserttitlegraphic\empty%
         \node[anchor=south, inner sep=0cm] at ([yshift=3cm]current page.south) {\includegraphics[width=\paperwidth]{example-image-16x9}};
       \else
        \node[anchor=south, inner sep=0cm] at ([yshift=3cm]current page.south) {\inserttitlegraphic};
       \fi     
   \end{tikzpicture}   
}


\begin{document}
   \begin{frame}[plain]
       \titlepage
   \end{frame}
   \section{Sec 1}
   \begin{frame}{Title}
       \blindtext
   \end{frame}
   \section{Sec 2}
   \begin{frame}{Title 2}
       \framesubtitle{Subtitle}
       \blindtext
   \end{frame}

\end{document}

在此处输入图片描述

或者,如果您想剪辑图像以便看到图像的中心:

\documentclass[10pt,%
aspectratio=1609,%
]{beamer}

\usepackage{mwe}
\usepackage{tikz}
%\usepackage{xcolor}

\title{TITLE}
\author{NAME}
\institute{INSTITUT}
\date{DATE}
\titlegraphic{\includegraphics[width=\paperwidth]{example-image-duck}}

%beamertheme.sty
\setbeamertemplate{navigation symbols}{}

%beamercolortheme.sty
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{structure}{fg=white}
\setbeamercolor*{section in toc}{fg=gray}
\setbeamercolor*{framtitle}{fg=white}
\setbeamercolor*{section}{fg=white}
\setbeamercolor*{normal text}{fg=gray}
\setbeamercolor*{foot}{fg=gray,bg=white}
\setbeamercolor*{title}{fg=white}
\setbeamercolor*{title page header}{fg=white}

%beamerinnertheme.sty
\defbeamertemplate*{title page}{test}[1][]
{
   \begin{tikzpicture}[remember picture,overlay]
       \node[fill=blue,minimum height=1cm,text width=\paperwidth] at ([yshift=2.5cm]current page.south) {\hspace{4cm}\usebeamerfont{title}\inserttitle};
       \fill[color=green] (current page.south west) rectangle ++(2.95,1.9);
       \node[fill=red,minimum height=1.9cm,text width=\paperwidth-6.5cm] at ([yshift=0.95cm]current page.south) {\hspace{0.9cm}\usebeamerfont{author}\insertauthor\par\vskip0.1cm \hspace{0.9cm}\usebeamerfont{author}\insertdate};
       \node[anchor=south east, inner sep =0.1cm] at (current page.south east) {\includegraphics[width=2.8cm]{example-image-b}};
       \begin{scope}
         \clip ([yshift=3cm]current page.south west) rectangle (current page.north east);
         \ifx\inserttitlegraphic\empty%
           \node[anchor=south, inner sep=0cm] at ([yshift=3cm]current page.south) {\includegraphics[width=\paperwidth]{example-image-16x9}};
         \else
          \node[inner sep=0cm] at ([yshift=1.5cm]current page.center) {\inserttitlegraphic};
         \fi     
       \end{scope}
   \end{tikzpicture}   
}

\begin{document}
   \begin{frame}[plain]
       \titlepage
   \end{frame}
   \section{Sec 1}
   \begin{frame}{Title}
       \blindtext
   \end{frame}
   \section{Sec 2}
   \begin{frame}{Title 2}
       \framesubtitle{Subtitle}
       \blindtext
   \end{frame}

\end{document}

在此处输入图片描述

相关内容