30

Is it possible to customize frame number like figure below?enter image description here

1

3 Answers 3

31

Below I present two options:

\documentclass{beamer}
\usepackage{tikz}

\definecolor{color1}{RGB}{173,216,230}
\definecolor{color2}{RGB}{255,140,0}

\newcounter{totavalue}

\def\aux{1}
\def\radius{20pt}

\newcommand\circcounteri{%
\ifnum\inserttotalframenumber<2\relax
\else
  \setcounter{totavalue}{\inserttotalframenumber}%
\fi%
\pgfmathsetmacro{\aux}{360/\thetotavalue}%
\begin{tikzpicture}[overlay]
  \fill[color1] 
    (0,0) -- (0:\radius) arc  (0:360:\radius) -- cycle;
  \fill[color2] 
    (0,0) -- (90:\radius) arc  (90:90-\insertframenumber*\aux:\radius) -- cycle;
  \node[font=\color{white}] at (0,0) {\strut\Large\insertframenumber};
\end{tikzpicture}%
}

\addtobeamertemplate{headline}{}{\vskip1cm\hspace*{15pt}smash\circcounteri\hfill}

\newcommand\TestFr{\begin{frame}
test
\end{frame}}

\begin{document}

\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr
\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr
\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr
\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr

\end{document}

enter image description here

The second fancier option (this might take longer to process for a presentation with many frames):

\documentclass{beamer}
\usepackage{tikz}

\definecolor{color1}{RGB}{173,216,230}
\definecolor{color2}{RGB}{255,140,0}

\newcounter{totavalue}
\newcounter{parvalue}

\def\aux{1}
\def\radius{20pt}
\def\step{4pt}

\newcommand\circcounter{%
\ifnum\inserttotalframenumber<2\relax
\else
  \setcounter{totavalue}{\inserttotalframenumber}
  \setcounter{parvalue}{\insertframenumber}
  \ifnum\inserttotalframenumber>45\relax
    \renewcommand\step{0pt}
  \fi%
  \pgfmathsetmacro{\aux}{360/\thetotavalue}
  \begin{tikzpicture}[remember picture,overlay,rotate=90+\aux]
  \foreach \i in {0,1,...,\thetotavalue}
    \fill[color1] 
      (0,0) -- (-\i*\aux:\radius) arc  (-\i*\aux:-(\i+1)*\aux+\step:\radius) -- cycle;
  \foreach \i in {1,...,\insertframenumber}
    \fill[color2] 
      (0,0) -- (-\i*\aux:\radius) arc  (-\i*\aux:-(\i+1)*\aux+\step:\radius) -- cycle;
  \fill[white] circle (\radius/2);
  \node at (0,0) {\large\insertframenumber}; 
  \end{tikzpicture}%
\fi%
}

\addtobeamertemplate{headline}{}{\vskip1cm\hfill\circcounter\hspace*{1cm}}

\newcommand\TestFr{\begin{frame}
test
\end{frame}}

\begin{document}

\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr
\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr
\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr\TestFr

\end{document}

enter image description here

3
  • thx, it works perfect
    – user49875
    Apr 14, 2014 at 19:51
  • But it doesnt work by lualatex when I use luapersian package and it has some errors like : ! TeX capacity exceeded, sorry [input stack size=5000].
    – user49875
    Apr 14, 2014 at 19:52
  • @user49875 I'm sorry to hear that; unfortunately, I don't have the luapersian package, so I cannot do any tests to diagnose the problem. You could consider opening a follow-up question mentioning the problem there and providing a minimal version of the code (a little test document like the one in the answers) that is not working. Apr 14, 2014 at 19:56
16

Basically, this answer is just a minor revision from my previous one Visual counter for LaTeX? and I will present a few version, all customizable through a user-friendly key-value interface.

From the original solution, a few changes should be performed:

  • removed beamer useless option;
  • set radius and thickness options to the same value to get sectors;
  • set a negative value to segment distance to avoid separation between sectors;
  • added the page number through \insertframenumber.

And here it is an example:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}

\setbeamertemplate{navigation symbols}{}

\pgfkeys{/visual counter/.cd,
 thickness/.store in=\thickness,
 thickness=0.4ex,
 radius/.store in=\radius,
 radius=1.5ex,
 segment distance/.store in=\segdist,
 segment distance=8,
 color current frame/.store in=\colcurrframe,
 color current frame=orange,
 color old frame/.store in=\cololdframe,
 color old frame=blue,
 color next frame/.store in=\colnextframe,
 color next frame=gray!30,
 color page number/.store in=\colpagenum,
 color page number=white,
 current value/.store in=\currentv,
 current value=1,
 total value/.store in=\totalv,
 total value=2,
 circled page number/.code={
    \begin{tikzpicture}[fill color/.style={}]
     \pgfkeys{/visual counter/.cd, 
       current value=\insertframenumber,
       total value=\inserttotalframenumber,
     }
    \pgfmathtruncatemacro\current{\currentv+1}
    \def\tot{\totalv}
    \def\radiusout{\radius}
    \def\radiusin{\radius-\thickness}

    \foreach \s in {1,...,\tot}
    {
      \ifnum\s>\current%
        \tikzset{fill color/.append style={\colnextframe}}%
      \fi%
      \ifnum\s=\current%
        \tikzset{fill color/.append style={\colcurrframe}}%
      \fi%
      \ifnum\s<\current%
        \tikzset{fill color/.append style={\cololdframe}}%
      \fi%
      \fill[fill color]
        ({90-360/\tot * (\s - 1)-\segdist}:\radiusout) arc 
        ({90-360/\tot * (\s - 1)-\segdist}:{90-360/\tot * (\s)+\segdist}:\radiusout) --
        ({90-360/\tot * (\s)+\segdist}:\radiusin) arc 
        ({90-360/\tot * (\s)+\segdist}:{90-360/\tot * (\s - 1)-\segdist}:\radiusin);
        % new addition
        \node[inner sep=0pt,text=\colpagenum] at (0,0){\insertframenumber};
    }
    \end{tikzpicture}
 },
}

% new footline with 
\setbeamertemplate{footline}{
\begin{beamercolorbox}[wd=0.95\textwidth, ht=2ex,dp=1ex,sep=1ex]{footline}
\hfill%
\tikz\node[/visual counter/.cd,
segment distance=-2pt,
radius=0.5cm, thickness=0.5cm,
color old frame=orange!50,
color current frame=cyan!80!gray!50,
color next frame=cyan!80!gray!50,
circled page number,
]{};
\end{beamercolorbox}
}

\begin{document}

\begin{frame}{Title}
bla bla bla

\end{frame}


\begin{frame}{Something else}
bla bla bla

\end{frame}

\begin{frame}{Different title}
bla bla bla
\end{frame}

\begin{frame}{Another one}
bla bla bla

\end{frame}

\begin{frame}{Final}
bla bla bla

\end{frame}

\end{document}

The result:

enter image description here

Just for demonstration, with a simple change of the footline template in the previous document into:

% new footline with 
\setbeamertemplate{footline}{
\begin{beamercolorbox}[wd=0.95\textwidth, ht=2ex,dp=1ex,sep=1ex]{footline}
\hfill%
\tikz\node[/visual counter/.cd, beamer=true,
radius=0.5cm, thickness=0.225cm,
color old frame=orange!80,
color current frame=cyan!80!gray!80,
color next frame=cyan!80!gray!80,
color page number=black,
circled page number,
]{};
\end{beamercolorbox}
}

it is possible to achieve the same result of Gonzalo's fancy option:

enter image description here

With:

% new footline with 
\setbeamertemplate{footline}{
\begin{beamercolorbox}[wd=0.95\textwidth, ht=2ex,dp=1ex,sep=1ex]{footline}
\hfill%
\tikz\node[/visual counter/.cd, beamer=true,
radius=0.5cm, thickness=0.175cm,
color old frame=cyan!80!gray!80, %       <= just set a different coloring
color current frame=orange!80,
color next frame=gray!80,
color page number=black,
circled page number,
]{};
\end{beamercolorbox}
}

the result becomes:

enter image description here

Another possibility is to have different thickness for frames to be appear compared to current frame and frames already appeared; for this, we should just change the thickness value of circled page number key:

circled page number/.code={
    \begin{tikzpicture}[fill color/.style={}]
     \pgfkeys{/visual counter/.cd, 
       current value=\insertframenumber-1,
       total value=\inserttotalframenumber,
     }
    \pgfmathtruncatemacro\current{\currentv+1}
    \pgfmathtruncatemacro\tot{\totalv}
    \def\radiusout{\radius}
    \def\radiusin{\radius-\thickness}

    \foreach \s in {1,...,\tot}
    {
      \ifnum\s>\current%
        \tikzset{fill color/.append style={\colnextframe}}%
        \pgfkeys{/visual counter/thickness={0.1cm}}%            <= new addition
      \fi%
      \ifnum\s=\current%
        \tikzset{fill color/.append style={\colcurrframe}}%
      \fi%
      \ifnum\s<\current%
        \tikzset{fill color/.append style={\cololdframe}}%
      \fi%
      \fill[fill color]
        ({90-360/\tot * (\s - 1)-\segdist}:\radiusout) arc 
        ({90-360/\tot * (\s - 1)-\segdist}:{90-360/\tot * (\s)+\segdist}:\radiusout) --
        ({90-360/\tot * (\s)+\segdist}:\radiusin) arc 
        ({90-360/\tot * (\s)+\segdist}:{90-360/\tot * (\s - 1)-\segdist}:\radiusin);
        % new addition
        \node[inner sep=0pt,text=\colpagenum] at (0,0){\insertframenumber};
    }
    \end{tikzpicture}
 },

(of course introducing another key would be far way better, but it's quite easy). It leads to:

enter image description here

3
  • It doesnt work by lualatex when I use luapersian package and it has some errors like : ! TeX capacity exceeded, sorry [input stack size=5000].
    – user49875
    Apr 14, 2014 at 19:55
  • @user49875 as I said in a comment to my answer, I think the best thing to do here is to ask a follow-up question. Apr 14, 2014 at 19:56
  • @user49875: I agree with Gonzalo, a fresh question would be better. Like him, I don't have luapersian package; however, I can tell you that testing the documents with lualatex, the compilation was fine both times. Apr 15, 2014 at 11:06
6

To expand on samcarter's comment, this is how such a counter can be displayed using the visualcounter module in ConTeXt. (Full disclosure: I am author of visual counter module).

First, we need to define a Metapost graphic that draws the appropriate shapes. See the documentation for what the predefined parameters mean:

\usemodule[visualcounter]

\unprotect
\definevisualcounter
  [clock]
  [      \c!mp=visualcounter::clock,
     \c!offset=0.5EmWidth,
  ]

\startuseMPgraphic{visualcounter::clock}
  begingroup ;

  \includeMPgraphic{visualcounter::initialization}

  draw fullcircle scaled 10pt;

  if (last_counter > 0) and (current_counter > 0) :
      % label
      newpicture countertext     ; countertext     := textext("\visualcounterparameter\c!text");
      newpicture max_countertext ; max_countertext := textext("\visualcounterparameter{\c!max\c!text}");

      newnumeric diameter;
      diameter := max(bbwidth(max_countertext), bbheight(max_countertext)) 
                   + 2*\visualcounterparameter\c!offset;

      newpath circle ; circle := reverse (fullcircle scaled diameter) rotated 90;

      newnumeric timescale; timescale := arclength (circle)/last_counter ;
      newpair current; current := point (current_counter*timescale) on circle;
      newpath slice;   slice := origin -- (circle cutafter current) -- cycle ;

      fill circle withcolor future_color;
      fill slice withcolor past_color;
      label (countertext, origin) withcolor \visualcounterparameter\c!color ;

  fi;
  endgroup ;

\stopuseMPgraphic
\protect

Then, it is straightforward to tie this to any ConTeXt counter. For example:

\definecounter[test]

\definevisualcounter
  [test]
  [clock]
  [
    style=bold,
    color=white,
    counter=test,
  ]


\starttext

\dontleavehmode
\dorecurse{10}{\incrementcounter[test]\usevisualcounter{test}\quad}

\stoptext

which gives:

enter image description here

The label is drawn according to the number conversion specified by the counter. So, if you change:

\definecounter[test][numberconversion=Characters]

you will get

enter image description here

To use this with pagenumbers, use:

\definevisualcounter
      [page] % use any identifier
      [clock]
      [....
       counter=userpage,
       ....]

and then use

 \usevisualcounter{page}

wherever you want the page number.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .