Can anybody tell me if it is possible to have page numbering on the side of the page? I mean on the right side on odd pages and on the left side on even pages.
3 Answers
I have followed up on the solution proposed by alexises, completing the code.
\documentclass[twoside]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{fancyhdr}
\fancypagestyle{Plain}{%
\fancyhf{}
\fancyfoot[EC]{%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=3cm,font=\bfseries] (number) at (current page.west) {\Huge[\thepage]};
\end{tikzpicture}
}%
\fancyfoot[OC]{%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-3cm,font=\bfseries] (number) at (current page.east) {\Huge[\thepage]};
\end{tikzpicture}
}%
}
\fancypagestyle{nonums}{%
\fancyhf{}
\fancyfoot[OC]{}
\fancyfoot[EC]{}
}
\pagestyle{Plain}
\begin{document}
\lipsum[1-10]
\lipsum[11-15]
\thispagestyle{nonums}
\lipsum[16-18]
\end{document}
For a page without the page number use \thispagestyle{nonums}
at an appropriate point in the document.
Screenshot:
Later:
I wanted an approach that did not rely on the twoside
option. tikzpagenodes.sty
makes this possible because the locations of the page numbers are relative to the current text block, not the edge of the page.
\documentclass{article} %% Use [twoside] if needed
\usepackage{lipsum}
\usepackage{tikzpagenodes}
\usepackage{fancyhdr}
\fancypagestyle{Plain}{%
\fancyhf{}
\fancyfoot[C]{%
\ifodd\thepage
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=2cm,font=\bfseries] (number) at (current page text area.east) {\Huge[\thepage]};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-2cm,font=\bfseries] (number) at (current page text area.west) {\Huge[\thepage]};
\end{tikzpicture}
\fi
}%
}
\fancypagestyle{nonums}{%
\fancyhf{}
\fancyfoot[C]{}
}
\pagestyle{Plain}
\begin{document}
\lipsum[1-10]
\lipsum[11-15]
\thispagestyle{nonums}
\lipsum[16-18]
\end{document}
Here is the non-twoside
output:
And here is the twoside
output:
-
your solutions works very, very well! thank you for helping me. I use \thispagestyle{empty}, because on the pages without page numbers there is no header, too. thank you once more!– AshrakAug 7, 2014 at 16:09
-
It's a bit rude of you to post a fully fleshed out version of @alexises solution when you haven't up-voted his answer! :) (There's currently one up-vote for his solution and it's mine!)– user30471Aug 8, 2014 at 0:48
-
Actually, the code, as presented, produced numerous TeX errors: 1) \textbf requires an argument -- \bfseries is the thing to use; 2) The use of math mode
\[...\]
in the Tikz node produced errors; 2) There were two missing ';' characters. I did not want to draw attention to the problems. Will Durant: "To speak ill of others is a dishonest way of praising ourselves. . . let us be above such transparent egotism." I simply presented an approach based on what was essentially a very good idea.– sgmoyeAug 8, 2014 at 9:55 -
@Andrew -- You are correct, however, I should have up voted the answer, which I have done. Thanks.– sgmoyeAug 8, 2014 at 10:18
You should consider using TikZ
with fancyhdr
\fancypagestyle{plain}{%
\fancyhf{}
\fancyfoot[EC]{%
\begin{tikz}[overlay]
\node[font=\textbf,xshift=0.5cm] (number) at (current page.west) {\[~\thepage~\]}
\end{tikz}
}%
\fancyfoot[OC]{%
\begin{tikz}[overlay]
\node[font=\textbf,xshift=0.5cm] (number) at (current page.east) {\[~\thepage~\]}
\end{tikz}
}%
}
-
A full document and a screen shot would make this a real answer ;-)– user31729Aug 6, 2014 at 21:37
Another way of doing this using the background package. Stealing from the manual a little, you can get:
(I could only display an even page next to an odd page...)
The LaTeX for this is fairly easy:
\documentclass{article}
\usepackage{lipsum}
\usepackage[pages=all,color=black,opacity=1,scale=4,contents={},angle=0,%
contents={}]{background}
\usepackage{ifthen}
\AddEverypageHook{\ifthenelse{\isodd{\value{page}}}%
{\backgroundsetup{position={0,-0.15\textheight}, contents={[\thepage]}}}%
{\backgroundsetup{position={0.34\textwidth,-0.15\textheight}, contents={[\thepage]}}}%
\BgMaterial%
}
\pagestyle{empty}
\begin{document}
\lipsum\lipsum\lipsum\lipsum
\end{document}
The placement of the page numbers is a little haphazard and could be improved. I don't really like the format of [x] for the page numbering, but for this I followed the OP. I would prefer something like a greyed -x-. It's also not hard to put the number in a \fbox
etc.
Finally, I should say that I am cheating a little here because background
uses tikz
behind the scenes, so this is similar to the solution that @alexises has already posted.
Edit
If you want to drop the page numbers from some pages then you can do it by adding using the following modification and putting \PageNumberfalse
on the pages where you don't ant numbers (this will only take effect for one page):
\documentclass{article}
\usepackage{lipsum}
\usepackage[pages=all,color=black,opacity=1,scale=4,contents={},angle=0,%
contents={}]{background}
\newif\ifPageNumber\PageNumbertrue
\AddEverypageHook{%
\ifPageNumber%
\ifodd\value{page}%
\backgroundsetup{position={0,-0.15\textheight}, contents={[\thepage]}}%
\else%
\backgroundsetup{position={0.34\textwidth,-0.15\textheight}, contents={[\thepage]}}%
\fi
\BgMaterial%
\fi\global\PageNumbertrue% by default number all pages
}
\pagestyle{empty}
\begin{document}
\lipsum\lipsum\PageNumberfalse\lipsum\lipsum
\end{document}
(For good measure I dropped the use of the ifthen
package...not sure why I used it before:)
-
Andrew, your solution is very good and works well for me. thank you. the only problem is that command \NoBgThispage doesn't work. I need some pages without page number– AshrakAug 7, 2014 at 11:07
-
@user60291 I've just added a quick hack for manually dropping some of the page numbers.– user30471Aug 7, 2014 at 11:42
-
Andrew, it works! thank you very much for your help. I'm a beginner :)– AshrakAug 7, 2014 at 12:52
-
@Zbynek No problem. Glad to help!– user30471Aug 7, 2014 at 12:55
-
Andrew, another problem. second solution causes that header and footer disappear everywhere :(– AshrakAug 7, 2014 at 15:32
\documentclass{...}
and ending with\end{document}
.scrlayer-scrpage
.