6

Please consider this MWE:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
        node[midway,align=center,font=\LARGE,text=white] {\bfseries\thepage}; % From https://tex.stackexchange.com/a/443744/152550
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

Example\newpage Another example

\end{document}

MWE output

What I want

I want to implement two buttons that are drawings made with tikzpicture, one for previous page and the other for next page (click on them):

What I want

What I have done

I am not able to add these drawings around the page number. The draw is an arrow:

\begin{tikzpicture}[remember picture,overlay]
    \draw[line width=1mm,red] (.3,.3) -- (0,0) -- (.3,-.3);
\end{tikzpicture}

Arrow pointing to the left

I tried to use coordinates with no effects, and tried to use the position of current page.south west + a shift but I couldn't:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm) node[midway,align=center,font=\LARGE,text=white] {\bfseries\thepage}; % From https://tex.stackexchange.com/a/443744/152550
        \draw[line width=1mm,white] (current page.south west) -- ++(.5cm,.5cm) -- (.3,-.3); % This should be placed near the page number, and there should be another arrow pointing to the right
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

Example\newpage Another example

\end{document}

What I have done

How can we place those arrows near the page number?

  • 1
    Using the tikzpagenodes package, there is (currnet page footer area), but you would still need fancyhdr or everypage to draw it. The thing to remember about footers and headers is that they are actually single lines of text, similar to \hbox to \textwidth{\rlap{left text}\hfill center text \hfill\llap{right text}}. – John Kormylo Feb 23 at 16:39
6

How about

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
        node[midway,align=center,font=\LARGE\bfseries,text=white] 
        (pageno-\number\value{page}) {\thepage}; % From https://tex.stackexchange.com/a/443744/152550
        \draw[white,ultra thick,line cap=round,line join=round] 
         ([xshift=-\paperwidth/4]pageno-\number\value{page}.south)
         --  ([xshift=-\paperwidth/4-7pt]pageno-\number\value{page}.center)
         -- ([xshift=-\paperwidth/4]pageno-\number\value{page}.north)
         ([xshift=\paperwidth/4]pageno-\number\value{page}.south)
         --  ([xshift=\paperwidth/4+7pt]pageno-\number\value{page}.center)
         -- ([xshift=\paperwidth/4]pageno-\number\value{page}.north);
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

Example\newpage Another example

\end{document}

enter image description here

Here is a more versatile version. The arrows only appear when it makes sense, and by clicking on them you move to the previous or next page.

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{tikz}
\usepackage{hyperref}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newsavebox{\manoooharrowL}
\newsavebox{\manoooharrowR}
\sbox\manoooharrowR{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\sbox\manoooharrowL{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (-7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\fancyhf{}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
        node[midway,align=center,font=\LARGE\bfseries,text=white,xscale=1.5] 
        (pageno-\number\value{page}) 
        {\thepage}; % From https://tex.stackexchange.com/a/443744/152550
        \ifnum\value{page}<\getpagerefnumber{LastPage}
         \path ([xshift=\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}+1}{\usebox\manoooharrowR}};
        \fi
        \ifnum\value{page}>1
         \path ([xshift=-\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}-1}{\usebox\manoooharrowL}};
        \fi
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

Example
\newpage 
Another example
\newpage 
Yet another example
\newpage 
Last page

\end{document}

enter image description here

| improve this answer | |
  • Thank you so much!! You have done what I wanted. I just replaced ultra thick with line width=1mm since I think it is thin (in this case I should increase the thickness of the \thepage but I did not how to do it, only got a small thickness by adding \bfseries). – manooooh Feb 23 at 15:50
  • 1
    @manooooh You can make it arbitrarily fat by using xscale=1.5, say, in the node options. – user194703 Feb 23 at 15:54
  • 1
    @manooooh I added a more versatile version with hyperlinks and somewhat more intelligent arrows. (One can of course add further arrows to jump to the last and/or first page, say.) – user194703 Feb 23 at 16:18
  • This works like a charm!!! I was going to post another question asking about your last code. Look! imgur.com/a/8JTYjm8 – manooooh Feb 23 at 16:22
  • 1
    @manooooh Sorry, was offline. Yes, ocgx is great, especially if its grand master AlexG is dealing with it. Normal mortals and cats often use more mundane tools. ;-) – user194703 Feb 23 at 18:40
4

Here is a very simple approach:

Output

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{tikz}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        % From https://tex.stackexchange.com/a/443744/152550
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm) 
        node[midway,align=center,font=\LARGE,text=white] (pgNum){\bfseries\thepage};
        % Left arrow
        \node[left of=pgNum, xshift=-3cm, scale=4, 
            path picture={\draw[line width=1mm, red] (.3,.3) -- (0,0) -- (.3,-.3);}] {};
        % Right arrow
        \node[right of=pgNum, xshift=3cm, scale=4, 
            path picture={\draw[line width=1mm, red] (-.3,-.3) -- (0,0) -- (-.3,.3);}] {};
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

Example\newpage Another example

\end{document}
| improve this answer | |
  • Thanks for the neat answer, I like your proposal! – manooooh Feb 23 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.