You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Beamer模板标题栏与侧边栏冲突:侧边栏无法铺满幻灯片高度

Beamer侧边栏高度铺满及标题栏遮挡问题修复

问题

  • 自定义进度条样式的标题栏(headline)遮挡幻灯片顶部内容区域
  • 右侧侧边栏无法垂直铺满整个幻灯片高度

解决方法及关键修改

1. 修正标题栏高度计算

原标题栏的tikzpicture包含超出边界的章节名称节点,加上额外的\vskip6pt,导致Beamer无法正确识别标题栏实际高度,进而挤压内容区域。通过以下调整修复:

  • 用\raisebox{-0.4cm}将标题栏整体上移,抵消下方节点的垂直占用
  • 添加\setbeamersize{headline=0.8cm}明确指定标题栏高度,让Beamer正确预留顶部空间

2. 调整侧边栏布局

  • 移除\useoutertheme中的height=0cm参数,该参数会限制侧边栏高度
  • 重新定义侧边栏模板,使其从页面顶部直接延伸至底部,不受标题栏和页脚影响

修改后的完整代码

\documentclass[aspectratio=169]{beamer}

% Tikz package
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{scalerel}
\usepackage{amsmath}
\usepackage{totcount}
\usepackage{refcount}
\usetikzlibrary{patterns.meta}
\usetikzlibrary{fadings,patterns,shadows}

\newenvironment{frameMain}[1]
{
%title placement
\renewcommand{\frametitle}[1]{
    \section{##1}
    \begin{tikzpicture}[remember picture,overlay]
          \node[anchor=west, text=black, font=\Huge\selectfont] at ([xshift=30px]current page.west) {
          
            \scaleto{\MakeUppercase{##1}}{1.3em}};
          
    \end{tikzpicture}}

    
    \begin{frame}
    
        \frametitle{#1}}
{
    
    \end{frame}
}

\newenvironment{myframe}[1]
{
    \let\oldframetitle\frametitle
    \renewcommand{\frametitle}[1]{
        \subsection{##1}
        \oldframetitle{##1}
    }
    \begin{frame}
        \begin{tikzpicture}[remember picture,overlay]
            \node[ align=right, anchor=south east, text=black, font=\selectfont] at ([xshift=0px, yshift=1em]current page.south east) {
                   \insertframenumber\,/\,\inserttotalframenumber
              };
        \end{tikzpicture}
        \frametitle{#1}}
{
    
    \end{frame}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% headline modified
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtotcounter{mysec}
\AtBeginSection{\addtocounter{mysec}{1}\label{mysec:\themysec}}
\newcounter{foo}

% 明确设置标题栏高度
\setbeamersize{headline=0.8cm}

\setbeamertemplate{headline}{%
    % 用\raisebox调整整体位置,抵消下方节点的垂直占用
    \raisebox{-0.4cm}{
    \vskip6pt
    \begin{tikzpicture}
        \path[draw=gray,rounded corners,preaction={fill, lightgray},pattern={Lines[angle=45,line width=3pt,distance=6pt]},pattern color=lightgray!50] (0,0) rectangle (.8\paperwidth,0.3);
        \path[rounded corners,preaction={fill, green!50!teal},pattern={Lines[angle=45,line width=3pt,distance=6pt]},pattern color=green!50!teal!50] (0,0) rectangle ({(\thepage-1)/(\insertdocumentendpage-1)*.8\paperwidth},0.3);
        \ifnum\thesection>0
            \path[rounded corners,preaction={fill, cyan!50!blue},pattern={Lines[angle=45,line width=3pt,distance=6pt]},pattern color=cyan!50!blue!50] (0,0) rectangle ({(\insertsectionstartpage-1)/(\insertdocumentendpage-1)*.8\paperwidth},0.3);
        \fi
        \foreach \x in {1,...,\totvalue{mysec}}{%
            \setcounterpageref{foo}{mysec:\x}
            \colorlet{seccol}{green!50!teal}
            \ifnum\thesection=\x
                \colorlet{seccol}{green!50!teal}
            \else
                \ifnum\thesection<\x
                    \colorlet{seccol}{lightgray}
                \else
                    \colorlet{seccol}{cyan!50!blue}
                \fi
            \fi     
            \node[circle,fill=seccol,draw=white,line width=1.5pt,minimum size=15pt] at ({(\thefoo-1)/(\insertdocumentendpage-1)*.8\paperwidth},0.15) {\x};
            \node[seccol] at ({(\thefoo-1)/(\insertdocumentendpage-1)*.8\paperwidth},-0.35) {\nameref{mysec:\x}};
        }
    \end{tikzpicture}%
    }
}

%%%%%%%%%
%sidebar modified
%%%%%%%%%

% 移除height=0cm参数,重新定义sidebar模板
\useoutertheme[right,width=35px]{sidebar}
\setbeamercolor{sidebar}{bg=brown}

% 重新定义sidebar背景,使其铺满整个页面高度
\setbeamertemplate{sidebar right}{%
  \vspace*{-\headheight}
  \vspace*{-\headsep}
  \begin{beamercolorbox}[wd=\sidebarwidth,ht=\paperheight]{sidebar}
  \end{beamercolorbox}
}

\begin{document}

\section{Title}
\begin{frame}{}
    \frametitle{Title}
    \framesubtitle{sub title}
    \author{Author}
    \date{date}
\end{frame}

\begin{frame}{Summary}
  \tableofcontents[currentsection]
\end{frame}  

\section{title2}
\begin{frame}{}
    \frametitle{title2}
\end{frame}

\subsection{SubTitle}
\begin{frame}{SubTitle}
    \begin{block}{normal bloc}
        normal bloc text
    \end{block}

    \begin{alertblock}{alert block}
        alert bloc text
    \end{alertblock}

    \begin{exampleblock}{example block}
        example block text
    \end{exampleblock}

    \begin{proof}
        a proof
    \end{proof}
\end{frame}

\end{document}

说明

  • 标题栏的\raisebox{-0.4cm}值可根据实际显示效果微调,确保章节名称不被遮挡且标题栏不挤压内容
  • 重新定义的sidebar right模板通过\vspace*{-\headheight}和\vspace*{-\headsep}抵消标题栏的顶部空间,让侧边栏从页面顶端开始延伸至底部

内容的提问来源于stack exchange,提问作者Lexa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 06:47:14