[Tex/LaTex] page numbers on the side of the page

marginspage-numbering

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

Best Answer

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