我有一个 beamer 代码(见下文),它使用 Metropolis 主题生成一些虚拟幻灯片。代码的这一特定部分
%****************************************
%****************************************
%****************************************
% PROBLEM HERE
%****************************************
%****************************************
%****************************************
\newcommand{\MenuSpacing}{50em}
\newcommand{\HorizontalPositionOfPageNumber}{11.5pt}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
% \definecolor{boxcol}{gray}{0.13}
\begin{beamercolorbox}[wd=\paperwidth,ht=4ex,dp=2.25ex]{palette}%
\hspace*{\MenuSpacing}
\MenuTextSize{\insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll \hskip0pt}}
\end{beamercolorbox}%
}
}
\setbeamercovered{dynamic}
%****************************************
%****************************************
%****************************************
负责在每张幻灯片的右上方插入菜单。菜单与页码的对齐是通过命令 \MenuSpacing 手动完成的。当添加新部分或删除旧部分时,必须通过多次重新编译和调整来重新建立对齐,这非常繁琐。所以,我正在寻找一种使这种对齐自动化的方法。您知道如何实现吗?
%!TEX program = xelatex
\documentclass[xcolor=dvipsnames,compress,aspectratio=169]{beamer} % Aspect ratio=16:9
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\usepackage{ragged2e}
\usepackage{mathtools}
\usepackage{changepage}
\usepackage{ifthen}
%****************************************
%****************************************
%****************************************
% DONE
%****************************************
%****************************************
%****************************************
%*< My Colors >
\definecolor{mywhite} {RGB}{245, 245, 247}
\definecolor{myblue} {RGB}{ 73, 135, 156}
\definecolor{myred} {RGB}{255, 73, 93}
%****************************************
%****************************************
%****************************************
\makeatletter
\newcommand{\srcsizetwo}{\@setfontsize{\srcsize}{2pt}{2pt}}
\newcommand{\srcsizethree}{\@setfontsize{\srcsize}{3pt}{3pt}}
\newcommand{\srcsizefour}{\@setfontsize{\srcsize}{4pt}{4pt}}
\newcommand{\srcsizefive}{\@setfontsize{\srcsize}{5pt}{5pt}}
\newcommand{\srcsizesix}{\@setfontsize{\srcsize}{6pt}{6pt}}
\newcommand{\srcsizeseven}{\@setfontsize{\srcsize}{7pt}{7pt}}
\newcommand{\srcsizeeight}{\@setfontsize{\srcsize}{8pt}{8pt}}
\newcommand{\srcsizenine}{\@setfontsize{\srcsize}{9pt}{9pt}}
\newcommand{\srcsizeten}{\@setfontsize{\srcsize}{10pt}{10pt}}
\newcommand{\srcsizeeleven}{\@setfontsize{\srcsize}{11pt}{11pt}}
\newcommand{\srcsizetwelve}{\@setfontsize{\srcsize}{12pt}{12pt}}
%****************************************
%****************************************
%****************************************
\newcommand{\crlf}{\textbackslash}
\newcommand{\MenuTextSize}{\srcsizefour}
\newcommand{\mytitlesize}{\srcsizeeleven}
\newcommand{\mytextsize}{\srcsizeeight}
\newcommand{\mytextsizesmall}{\srcsizeeight}
\newcommand{\mytextsizesmaller}{\srcsizeseven}
\newcommand{\mytextsizeevensmaller}{\srcsizesix}
%****************************************
%****************************************
%****************************************
%*< Slide Style >
\apptocmd{\frame}{}{\justifying}{}
\let\olditem\item
\renewcommand\item{\olditem\justifying}
\renewcommand{\indent}{\hspace*{1em}}
\setbeamertemplate{itemize/enumerate body begin}{\mytextsize}
\setbeamertemplate{itemize/enumerate subbody begin}{\mytextsize}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
%****************************************
%****************************************
%****************************************
%*< Slide Style >
%Loading Metropolis...
\usetheme{metropolis}
\usefonttheme{professionalfonts}
\defaultfontfeatures{Mapping=tex-text}
\setsansfont[BoldItalicFont={* Demi Bold Italic},
ItalicFont={* Demi Bold},
BoldFont={* Demi Bold},
% UprightFont={* Regular}]{Fira}
UprightFont={* Regular}]{Avenir Next}
% \setsansfont[BoldFont={Fira Sans}]{Fira Sans Light}
% \setmonofont{Fira Mono}
% \usepackage[sfdefault]{Fira Sans}
\newcommand{\mycolortheme}{myblue}
\newcommand{\mycolorbackground}{mywhite}
\newcommand{\colorforegroundoftheprogressbar}{myblue}
\newcommand{\colorbackgroundoftheprogressbar}{gray}
\metroset{progressbar=foot,numbering=none, titleformat frame=regular}
% \setbeamercolor{progress bar}{fg=airforceblue, bg=gray}
\setbeamercolor{progress bar}{fg=\colorforegroundoftheprogressbar, bg=\colorbackgroundoftheprogressbar}
\setbeamercolor{palette}{bg=Black!90}
\setbeamercolor{palettew}{bg=White}
\setbeamercolor{section in head/foot}{fg=white,bg=Black!97}
\beamertemplatenavigationsymbolsempty
% \setbeamertemplate{frametitle}{}
\setbeamertemplate{frametitle continuation}[from second][\nonumber]
\setbeamerfont{frametitle}{size=\mytitlesize,series=\bfseries\scshape}
\setbeamercolor{frametitle}{fg=Black,bg=white}
% \setbeamerfont{normal text}{size=\mytextsizesmall}
\setbeamerfont{caption}{series=\normalfont,size=\mytextsizesmaller}
%****************************************
%****************************************
%****************************************
% PROBLEM HERE
%****************************************
%****************************************
%****************************************
\newcommand{\MenuSpacing}{50em}
\newcommand{\HorizontalPositionOfPageNumber}{11.5pt}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
% \definecolor{boxcol}{gray}{0.13}
\begin{beamercolorbox}[wd=\paperwidth,ht=4ex,dp=2.25ex]{palette}%
\hspace*{\MenuSpacing}
\MenuTextSize{\insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll \hskip0pt}}
\end{beamercolorbox}%
}
}
\setbeamercovered{dynamic}
%****************************************
%****************************************
%****************************************
\setbeamertemplate{footline}{
\usebeamercolor[fg]{page number in head}%
\usebeamerfont{page number in head}%
\hfill
\srcsizefour{\color{black!30}\insertframenumber~|~\inserttotalframenumber}
\hspace{\HorizontalPositionOfPageNumber}
\vspace{8pt}
}
\date{}
\apptocmd{\frame}{}{\justifying}{}
%****************************************
%****************************************
%****************************************
% Loading chapters
\begin{document}
\maketitle
\AtBeginSection{}
\section{~~Section 1}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\section{~~Section 2}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\section{~~Section 3}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\section{~~Section 4}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\section{~~Section 5}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\section{~~Section 6}
\begin{frame}[t,fragile,allowframebreaks]\frametitle{}
\mytextsize
\justifying Dummy text\ldots
\end{frame}
\end{document}
答案1
您正在\hskip0pt plus1filll \hskip0pt
导航栏的右侧添加内容,这会使其左对齐。不要将导航栏左对齐,然后在其前面手动添加空间,而是使其右对齐:
\documentclass[xcolor=dvipsnames]{beamer}
\makeatletter
\newcommand{\srcsizefour}{\@setfontsize{\srcsize}{4pt}{4pt}}
\makeatother
\usetheme{moloch}% modern fork of the metropolis theme
\setbeamercolor{palette}{bg=Black!90}
\setbeamercolor{section in head/foot}{fg=white,bg=Black!97}
\newcommand{\HorizontalPositionOfPageNumber}{11.5pt}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=4ex,dp=2.25ex]{palette}%
\srcsizefour
\insertsectionnavigationhorizontal{\paperwidth}{\hskip0pt plus1filll \hskip0pt}{\hskip5pt}
\end{beamercolorbox}%
}
}
\setbeamertemplate{footline}{
\usebeamercolor[fg]{page number in head}%
\usebeamerfont{page number in head}%
\hfill
\srcsizefour\color{black!30}\insertframenumber~|~\inserttotalframenumber
\hspace{\HorizontalPositionOfPageNumber}
\vspace{8pt}
}
\addtobeamertemplate{section in head/foot}{\hskip0.1cm}{}
\begin{document}
\section{Section 1}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\section{Section 2}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\section{Section 3}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\section{Section 4}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\section{Section 5}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\section{Section 6}
\begin{frame}
\frametitle{}
Dummy text\ldots
\end{frame}
\end{document}