为什么我不能在这里使用 max()?

为什么我不能在这里使用 max()?

当我使用 Beamer 进行演示时,我喜欢在底部放一个条形图,直观地显示演示的进度。下面代码中有趣的部分是行上的划分node[fill=navfg,...]

\usebeamercolor{palette primary}
\colorlet{navfg}{fg!80!white}
\colorlet{navbg}{fg!40!white}
\newcommand{\navradius}{0.25ex}
\setbeamertemplate{footline}{
    \tikz\draw[text height=2*\navradius,inner sep=0ex,rounded corners=\navradius]
        node[fill=navbg,minimum width=\textwidth-\navradius](back){} (back.west)
        node[fill=navfg,minimum width=(\insertframenumber-1)/(\inserttotalframenumber-1)*(\textwidth-\navradius),right]{}
        (back.south) node[below]{}
        ;
}

效果很好,除了在第一次尝试使用此代码片段构建演示文稿时。在第一次构建期间,\inserttotalframenumber具有值1,因此这会除以零。明显的解决方法是使用max

node[fill=navfg,minimum width=(\insertframenumber-1)/max(1,\inserttotalframenumber-1)*(\textwidth-\navradius),right]{}

但这会导致错误:

! Missing \endcsname inserted.
<to be read again> 
                   \textwidth 
l.10 \begin{document}

!  ==> Fatal error occurred, no output PDF file produced!

为什么我会收到此错误?我该怎么做才能正确解决这个问题?

答案1

如果 TikZ 无法正确评估某些表达式,通常可以通过用括号括住表达式来帮助它。在你的例子中,

node[fill=navfg,minimum width={(\insertframenumber-1)/max(1,inserttotalframenumber-1)*(\textwidth-\navradius)},right]{}

工作正常。

相关内容