[Tex/LaTex] Landscape mode and page numbering

page-numberingtables

I am working with a document that has several pages that are in landscape mode. I do realize there are different ways of managing the document – for example, using sideways table with the rotating package – but I do want landscape mode with the pdflscape package. In landscape mode, the page in PDF will actually change orientation – which will make it easier for the vast majority of readers to read as the text will be oriented the right way for the reader (and likely the vast majority of readers of the document as few will print it out). The issue I have is that the page numbers are flipped – the page numbers appear at the top of the document when printed and not at the bottom. It is not easy to see this in the document itself; however, when printed the page numbers are oriented improperly as they are placed at the top of the page and not the bottom. The page numbers should appear toward the 2/4 side of the landscape page, not the 1/3 side. Is there someway to solve this issue? I would much prefer to set the page with landscape to make it easier to read for those reading online.

%% LyX 2.0.7 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{pdflscape}
\usepackage{rotating}

\makeatother

\usepackage{babel}
\begin{document}
Test 1 2 3.

\pagebreak{}

\begin{landscape}%
\begin{tabular}{|c|c|}
\hline 
1 & 2\tabularnewline
\hline 
\hline 
3 & 4\tabularnewline
\hline 
\end{tabular}\end{landscape}

\pagebreak{}

\begin{sidewaystable}%
\begin{tabular}{|c|c|}
\hline 
1 & 2\tabularnewline
\hline 
\hline 
3 & 4\tabularnewline
\hline 
\end{tabular}\end{sidewaystable}
\end{document}

Best Answer

Tikzpagenodes got confused by pdflandscape, so I had to do it the hard way.

\documentclass{article}
\usepackage{pdflscape}
\usepackage{tikz}

\begin{document}
Test 1 2 3.

\pagebreak{}

\begin{landscape}%
\thispagestyle{empty}
\begin{tikzpicture}[overlay]
\node[above] at (.5\linewidth,-\textwidth-\footskip) {\thepage};
\end{tikzpicture}

\begin{tabular}{|c|c|}
\hline 
1 & 2\\
\hline 
\hline 
3 & 4\\
\hline 
\end{tabular}
\end{landscape}

\end{document}

Here is an even more general solution using everypage:

\documentclass[english]{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{everypage}
\usepackage{lipsum}

\newlength{\hfoot}
\newlength{\vfoot}
\AddEverypageHook{\ifdim\textwidth=\linewidth\relax
\else\setlength{\hfoot}{-\topmargin}%
\addtolength{\hfoot}{-\headheight}%
\addtolength{\hfoot}{-\headsep}%
\addtolength{\hfoot}{-.5\linewidth}%
\ifodd\value{page}\setlength{\vfoot}{\oddsidemargin}%
\else\setlength{\vfoot}{\evensidemargin}\fi%
\addtolength{\vfoot}{\textheight}%
\addtolength{\vfoot}{\footskip}%
\raisebox{\hfoot}[0pt][0pt]{\rlap{\hspace{\vfoot}\rotatebox[origin=cB]{90}{\thepage}}}\fi}

\begin{document}
\noindent Test 1 2 3.

\pagebreak{}

\begin{landscape}%
\pagestyle{empty}
\lipsum[1-8]
\end{landscape}
\pagestyle{plain}

\end{document}

As far as I can tell, pdflscape uses the same margins only rotated 90^\circ. The top margin is actually the left margin, the right margin is actually the top margin, and so on.