6

I want to construct a series of circles which ranks shoulder to shoulder in every page footer. The number of circles is just the number of total pages, that is to say, each circle represents a page. At the center of each circle is the current page number.

It's easy to achieve this by \foreach from pgf if diametes of all these circles are same. However, I want the circle which represents the current page has a larger diameter.

The typeset is like the attached figure produced by the following MWE. Anyone can help me with this?

MWE:

\documentclass{article}
\usepackage{fancyhdr,geometry,color,tikz}
\geometry{showframe}

\begin{document}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.4pt}
some text...

\cfoot{
\begin{tikzpicture}
  \draw[fill=gray,text=white,radius=0.5](0,0)circle node{1};
  \draw[fill=red,text=white,radius=1](1.5,0)circle node{2};
  \draw[fill=gray,text=white,radius=0.5](3,0)circle node{3};  
\end{tikzpicture}
}
\end{document}

enter image description here

1 Answer 1

5

Something like that?

\documentclass{article}
\usepackage{fancyhdr,geometry,lastpage,refcount,lipsum,tikz}
\geometry{showframe}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.4pt}
some text...
\newcounter{lastpagenumber}%
\setcounter{lastpagenumber}{\getrefbykeydefault{LastPage}{page}{1}}%

\cfoot{\begin{tikzpicture}
\coordinate (cn-0);
\foreach \X [remember=\X as \LastX (initially 0)] in {1,...,\thelastpagenumber}
{\ifnum\X=\thepage
 \node[circle,fill=red,text=white,minimum size=1cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \else
 \node[circle,fill=gray,text=white,minimum size=0.5cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \fi
}
\end{tikzpicture}
}
\lipsum[1-31]
\end{document}

enter image description here

Of course, one can customize the output in many ways.

\documentclass{article}
\usepackage{fancyhdr,geometry,lastpage,refcount,lipsum,tikz}
\geometry{showframe}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.4pt}
some text...
\newcounter{lastpagenumber}%
\setcounter{lastpagenumber}{\getrefbykeydefault{LastPage}{page}{1}}%

\cfoot{\begin{tikzpicture}
\coordinate (cn-0);
\foreach \X [remember=\X as \LastX (initially 0)] in {1,...,\thelastpagenumber}
{\ifnum\X=\thepage
 \node[circle,draw,thick,font=\sffamily\Large\bfseries,fill=red,text=white,minimum size=1cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \else
 \node[circle,draw,font=\sffamily\bfseries,fill=gray,text=white,minimum size=0.5cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \fi
}
\end{tikzpicture}
}
\lipsum[1-31]
\end{document}

enter image description here

And if you find circles a bit dull, you could do

\documentclass{article}
\usepackage{fancyhdr,geometry,lastpage,refcount,lipsum,tikzducks,tikzlings}
\geometry{showframe}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{0.4pt}
some text...
\newcounter{lastpagenumber}%
\setcounter{lastpagenumber}{\getrefbykeydefault{LastPage}{page}{1}}%

\cfoot{\begin{tikzpicture}
\coordinate (cn-0);
\foreach \X [remember=\X as \LastX (initially 0)] in {1,...,\thelastpagenumber}
{\ifnum\X=\thepage
 \node[font=\sffamily\Large\bfseries,text=white,minimum size=1cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \begin{scope}[scale=0.4,on background layer,shift={(cn-\X.center)},yshift=-3em]
 \marmot
 \end{scope}
 \else
 \node[font=\sffamily\bfseries,text=black,minimum size=0.5cm,right=0pt of cn-\LastX] (cn-\X) {\X};
 \begin{scope}[scale=0.3,on background layer,shift={(cn-\X.center)},yshift=-3em]
 \koala
 \end{scope}
 \fi
}
\end{tikzpicture}
}
\lipsum[1-31]
\end{document}

enter image description here

10
  • 1
    Thank you so much for your excellent solutions! That's just what I want!
    – lyl
    Mar 10, 2019 at 5:08
  • @marmot can you please explain the statement \coordinate (cn-0);. What does cn mean in this context. Mar 10, 2019 at 5:12
  • @marmot \getrefbykeydefault{LastPage}{page}{1}, here how to understand the function of {1}. I don't find further explaination in refcount document.
    – lyl
    Mar 10, 2019 at 5:20
  • @lyl I literally copied it from page 4 of the lastpage documentation.
    – user121799
    Mar 10, 2019 at 5:22
  • @lyl cn is just a random name. (In my imagination it stands for circular node, but you could replace it by cute furry rodent, say, and it will still work.)
    – user121799
    Mar 10, 2019 at 5:30

You must log in to answer this question.

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