讲义页眉的更改

讲义页眉的更改

我遇到了一个奇怪的问题。当我在投影仪模式下运行代码时,我在每张幻灯片中使用的徽标(在右上角)停留在那里并且不会移动。当我尝试制作讲义时,徽标会改变位置并转到一个奇怪的地方。有什么想法吗?帮忙吗?这是我的 MWE:

\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer} 
%\documentclass[11 pt, handout,xcolor=pdftex,x11names,table]{beamer}
\usepackage{pgf, pgfpages, pgfplots}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{color}
\usepackage{pdfpages}
\usepackage[absolute,overlay]{textpos}
\mode<presentation>
{
    \usetheme{Madrid}
    \usecolortheme{orchid}
    \usecolortheme{whale}
}
\title[]{Hi}
\author {\Large{\emph{Me}}}
\date[\today]{\today \\ $ $ \\
\includegraphics[height=1.5cm]{logo.eps}}
\makeatletter
\def\strokeifnotempty{%
\expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
\let\@next=\relax
\else
\let\@next=\pgfstroke
\fi
\@next%
}
\makeatother
\mode<handout>
{
  \usepackage{pgf}
  \usepackage{pgfpages}
\pgfpagesdeclarelayout{2 on 1 boxed}
{
  \edef\pgfpageoptionheight{\the\paperheight} 
  \edef\pgfpageoptionwidth{\the\paperwidth}
  \edef\pgfpageoptionborder{10pt}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=2,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth%
  }
  \pgfpageslogicalpageoptions{2}
  {%
    border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
    border shrink=\pgfpageoptionborder,%
    resized width=0.85\pgfphysicalwidth,%
    resized height=.5\pgfphysicalheight,%
    center=\pgfpoint{0.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
  }%
  \pgfpageslogicalpageoptions{1}
  {%
    border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
    border shrink=\pgfpageoptionborder,%
    resized width=0.85\pgfphysicalwidth,%
    resized height=.5\pgfphysicalheight,%
    center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
  }%
  }
\IfFileExists{\jobname.aux}{
  \pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
  \nofiles
 }{}
}
\begin{document}
{
\begin{frame}
\titlepage
\end{frame}
}
\addtobeamertemplate{frametitle}{}{
\begin{textblock*}{100mm}(0.84\textwidth,0.07cm)
    \includegraphics[height=0.8cm]{logo.eps} 
\end{textblock*}
}
\begin{frame}
    \frametitle{Hi}
HEY
\end{frame}
\begin{frame}
    \frametitle{Material?}
My book                     
        \end{frame}
\begin{frame}
    \frametitle{Course Website}
Nothing
\end{frame}
\end{document} 

我也尝试包含徽标文件;但 .eps 格式不被接受,我无法上传它......

我需要补充一点,如果您想以讲义模式运行它,请注释第一行并取消注释第二行。

答案1

使用textpos选项absolute会导致使用时的输出不同(不使用 时pgfpages不会导致 选项出现问题),即使使用 也是如此,因为位置是相对于物理页面,而不是逻辑页面。handoutpgfpages\nofilesabsolute

要在标题中显示徽标,最好使用beamer为此目的设计的(外部)主题,最好与提供的\logo界面一起使用beamer,而不是使用textpos。不幸的是,我不知道有任何现有主题可以将徽标放在您想要的位置。

以下解决方案textpos完全避免使用,并尝试在一定程度上使用beamer\logo功能(并且希望无论使用哪个模板都仍然具有一些合理的行为),但它仍然不够优雅:

  • 模板中不能直接移动徽标位置sidebar right,因为徽标frametitle会放在其上方。因此,我们可以\insertlogosidebar right模板中关闭它...

    % prevent the logo from appearing in the usual position on pages
    \addtobeamertemplate{sidebar right}{%
        \let\insertlogo\relax% don't worry, the template is executed in a group!
    }{}
    
  • ...并将另一个放入模板\insertlogoframetitle,并放置在适当的位置:

    % modify the frametitle template in a generic manner
    % so that within it, \insertframetitle also inserts a right aligned box (apparently of no height/width) containing the logo
    % elsewhere, \insertframetitle behaves as normal and does not include this logo!
    \addtobeamertemplate{frametitle}{%
    \let\oldinsertframetitle\insertframetitle
    \def\insertframetitle{\makebox[\textwidth][l]{\oldinsertframetitle}\vbox to 0pt{\vtop{\vskip-0.6cm\makebox[0pt][r]{\insertlogo}}}}%
    }%
    {}%
    

    如果您希望水平位置更像原始示例,请在后面\hspace{1.5cm}添加。\insertlogo\def\insertframetitle

注意,框架标题中的徽标的定位方法并不好。

我还将其放在了您的 MWE 上下文中,并对其进行了一些更改:

  1. 用来\titlegraphic代替您之前在标题页上设置徽标的 hack。
  2. example-image-a从包装中使用mwe,因为我(和其他人)没有您使用的徽标。
  3. 减少了您使用的部分布局代码。我没有为了添加边框而pgfpages复制原始定义,而是声明了一个加载原始定义的布局。不过请注意,它与您的版本并不完全相同。2 on 1
  4. 尝试通过确保在调用和\nofiles之前至少进行 2 次正确的 LaTeX 运行来改进该问题。现在页脚中的计数器是正确的。(当然,您是否遇到任何问题取决于您在没有该模式的情况下编译文件的次数。)pgfpages\nofilesLastPagehandout这就是为什么我的代码这么长......
  5. \documentclass用一行替换其中一行\PassOptionsToClass,因为这样可以使差异更加清晰,并且只需一行来注释/取消注释,而不是两行。
  6. 删除了一些不需要的东西。
  7. frametitle修补程序移至序言部分。

完整代码:

\PassOptionsToClass{handout}{beamer}% just comment out this line to disable handout mode
\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer} 
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{mwe}% for example-image-a (requiring the package helps the package manager)

\mode<presentation>
{
    \usetheme{Madrid}
    \usecolortheme{orchid}
    \usecolortheme{whale}
}
\title{Hi}
\author{Me}
\date{\today}

% use the \logo and \titlegraphic facilities provided by beamer
\logo{\includegraphics[height=0.8cm]{example-image-a}}
\titlegraphic{\includegraphics[height=1.5cm]{example-image-a}}

% prevent the logo from appearing in the usual position on pages
\addtobeamertemplate{sidebar right}{%
    \let\insertlogo\relax% don't worry, the template is executed in a group!
}{}
% modify the frametitle template in a generic manner
% so that within it, \insertframetitle also inserts a right aligned box (apparently of no height/width) containing the logo
% elsewhere, \insertframetitle behaves as normal and does not include this logo!
\addtobeamertemplate{frametitle}{%
\let\oldinsertframetitle\insertframetitle
\def\insertframetitle{\makebox[\textwidth][l]{\oldinsertframetitle}\vbox to 0pt{\vtop{\vskip-0.6cm\makebox[0pt][r]{\insertlogo}}}}%
}%
{}%

\makeatletter

\mode<handout>
{
    % based on [Beamer handout: Problem when creating border around frames](http://tex.stackexchange.com/a/53606)
    \def\pgfpagesborderstrokeifnotempty{%
        \expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
        \else
        \expandafter\pgfstroke
        \fi
    }

    % count number of LaTeX runs to attempt to guess if we can activate pgfpages and execute \nofiles
    \newcommand*{\IfRanMoreThan}[1]{\ifnum\value{counttexrunsforpgfpages}>#1\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}%

    % following mostly borrowed from counttexruns.sty
    % can't just use that package directly;
    % have to split because we don't always want to update the counter (breaks latexmk)
    % when editing the file, should also delete \jobname.\counttexrunsforpgfpages@extension to allow recompilation enough times
    \newcounter{counttexrunsforpgfpages}%
    \newwrite\@counttexrunsforpgfpagesfile
    \def\counttexrunsforpgfpages@extension{pgfpages.ctr}%
    \IfFileExists{\jobname.\counttexrunsforpgfpages@extension}{%
      \immediate\openin\@counttexrunsforpgfpagesfile=\jobname.\counttexrunsforpgfpages@extension
      \immediate\read\@counttexrunsforpgfpagesfile to \@counttexrunsforpgfpages
      \immediate\read\@counttexrunsforpgfpagesfile to \@counttexrunsforpgfpages
      \immediate\closein\@counttexrunsforpgfpagesfile
      \setcounter{counttexrunsforpgfpages}{\@counttexrunsforpgfpages}
    }{}%
    \stepcounter{counttexrunsforpgfpages}%

    \IfRanMoreThan{2}{%hope file gets compiled enough times without pgfpages being active (only need to ensure the lines \pgfpagesuselayout and \nofiles are in this block, but save time by not loading the packages if not needed in current run)
        \usepackage{pgf}
        \usepackage{pgfpages}
        % extend the default definition of the '2 on 1' layout to add a border to each logical page,
        % without having to copy the whole of the original layout definition
        \pgfpagesdeclarelayout{2 on 1 boxed}%
        {%
            \pgfpagesuselayout{2 on 1}%
            \edef\pgfpageoptionborder{10pt}%change default value for border shrink
        }%
        {%
            \pgfpageslogicalpageoptions{1}{%
                border code=\pgfsetlinewidth{2pt}\pgfpagesborderstrokeifnotempty,
                resized width=0.85\pgfphysicalwidth,
            }%
            \pgfpageslogicalpageoptions{2}{%
                border code=\pgfsetlinewidth{2pt}\pgfpagesborderstrokeifnotempty,
                resized width=0.85\pgfphysicalwidth,
            }%
        }%
        \pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
        \nofiles
    }{%
        % save the number of runs to the file! also adjusted from counttexruns.sty
        \immediate\openout\@counttexrunsforpgfpagesfile=\jobname.\counttexrunsforpgfpages@extension
        \catcode`\%=11\relax
        \immediate\write\@counttexrunsforpgfpagesfile{%% This file
          '\jobname.\counttexrunsforpgfpages@extension' was not really generated by the package counttexruns}
        \catcode`\%=14\relax
        \immediate\write\@counttexrunsforpgfpagesfile{\arabic{counttexrunsforpgfpages}}
        \immediate\closeout\@counttexrunsforpgfpagesfile
    }%
}% end \mode<handout>
\makeatother

\begin{document}

% \titlepage doesn't use \frametitle, so the logo only appears there in the \titlegraphic
\begin{frame}
\titlepage
\end{frame}

\begin{frame}
    \frametitle{Hi}
    HEY
\end{frame}
\begin{frame}
    \frametitle{Material?}
    My book
\end{frame}
\begin{frame}
    \frametitle{Course Website}
    Nothing
\end{frame}

\end{document}

输出的第一页(物理页)

答案2

这有效:只需删除absolute选项textpos并重新调整徽标位置:

%\documentclass [11 pt, xcolor=pdftex,x11names,table]{beamer} 
\documentclass[11 pt, handout,x11names,table]{beamer}
\usepackage{pgf, pgfpages, pgfplots}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
%\usepackage{color}
%\usepackage{pdfpages}
\usepackage[overlay]{textpos}
\mode<presentation>
{
    \usetheme{Madrid}
    \usecolortheme{orchid}
    \usecolortheme{whale}
}
\title[]{Hi}
\author {\Large{\emph{Me}}}
\date[\today]{\today \\ $ $ \\
\includegraphics[height=1.5cm]{example-image}}
\makeatletter
\def\strokeifnotempty{%
\expandafter\ifvoid\csname pgfpages@box@\the\pgf@cpn\endcsname
\let\@next=\relax
\else
\let\@next=\pgfstroke
\fi
\@next%
}
\makeatother
\mode<handout>
{
  \usepackage{pgf}
  \usepackage{pgfpages}
\pgfpagesdeclarelayout{2 on 1 boxed}
{
  \edef\pgfpageoptionheight{\the\paperheight} 
  \edef\pgfpageoptionwidth{\the\paperwidth}
  \edef\pgfpageoptionborder{10pt}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=2,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth%
  }
  \pgfpageslogicalpageoptions{2}
  {%
    border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
    border shrink=\pgfpageoptionborder,%
    resized width=0.85\pgfphysicalwidth,%
    resized height=.5\pgfphysicalheight,%
    center=\pgfpoint{0.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
  }%
  \pgfpageslogicalpageoptions{1}
  {%
    border code=\pgfsetlinewidth{2pt}\strokeifnotempty,%
    border shrink=\pgfpageoptionborder,%
    resized width=0.85\pgfphysicalwidth,%
    resized height=.5\pgfphysicalheight,%
    center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
  }%
  }
\IfFileExists{\jobname.aux}{
  \pgfpagesuselayout{2 on 1 boxed}[letterpaper, border shrink=5mm]
  \nofiles
 }{}
}
\begin{document}
{
\begin{frame}
\titlepage
\end{frame}
}
\addtobeamertemplate{frametitle}{}{
\begin{textblock*}{100mm}(0.84\textwidth,-0.9cm)
    \includegraphics[height=0.8cm]{example-image} 
\end{textblock*}
}
\begin{frame}
    \frametitle{Hi}
HEY
\end{frame}
\begin{frame}
    \frametitle{Material?}
My book                     
        \end{frame}
\begin{frame}
    \frametitle{Course Website}
Nothing
\end{frame}
\end{document}

相关内容