4

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.

enter image description here

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 6 '14 at 11:44
  • Another possible solution would include package scrlayer-scrpage. – Johannes_B Aug 6 '14 at 12:01
  • @ChristianHupfer That question doesn't address moving the page number to the (vertical) center of the page, it just places it on the outside of the header. – Torbjørn T. Aug 6 '14 at 12:19
  • @TorbjørnT. Sorry, I took the false link, I will look for another one – user31729 Aug 6 '14 at 12:21
  • Probably a MWE for this would be an empty article-document? – JF Meier Aug 6 '14 at 13:06
2

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:

Preview of bold page nums at side of page, including page with no number.

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:

Non-twoside output

And here is the twoside output:

enter image description here

  • 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! – Ashrak Aug 7 '14 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!) – Andrew Aug 8 '14 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. – sgmoye Aug 8 '14 at 9:55
  • @Andrew -- You are correct, however, I should have up voted the answer, which I have done. Thanks. – sgmoye Aug 8 '14 at 10:18
2

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 ;-) – user31729 Aug 6 '14 at 21:37
1

Another way of doing this using the background package. Stealing from the manual a little, you can get:

enter image description here

(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 – Ashrak Aug 7 '14 at 11:07
  • @user60291 I've just added a quick hack for manually dropping some of the page numbers. – Andrew Aug 7 '14 at 11:42
  • Andrew, it works! thank you very much for your help. I'm a beginner :) – Ashrak Aug 7 '14 at 12:52
  • @Zbynek No problem. Glad to help! – Andrew Aug 7 '14 at 12:55
  • Andrew, another problem. second solution causes that header and footer disappear everywhere :( – Ashrak Aug 7 '14 at 15:32

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.