2

I found here on tex.stackexchange.com an excellent & beautiful portrait-but-1-page-landscape-table snippet (see below).

This is exactly what I need, however I want a pagenumber, but when I comment out thispagestyle{empty}, then the pagenumber itself is not rotated. So that is still portrait.

How to get the footer/header also rotated? The rest need to stay the same (well functionally, so only impact a single page with table, \afterpage, PDF rendering, etc).

enter image description here

MWE:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum % Text before
\afterpage{%
    \clearpage% Flush earlier floats (otherwise order might not be correct)
  %  \thispagestyle{empty}% empty page style (?)
    \begin{landscape}% Landscape page
        \centering % Center table
        \begin{tabular}{llll}
            A & B & C & D \\
        \end{tabular}
        \captionof{table}{Table caption}% Add 'table' caption
    \end{landscape}
    \clearpage% Flush page
}
\lipsum % Text after
\end{document}
3

Here, I use my \atxy{x-loc}{y-loc}{text} technique from What are the ways to position things absolutely on the page? to place something at an arbitrary position on the page. The location I select is {\dimexpr\paperwidth-1in}{.5\paperheight} which is horizontally centered relative to the new orientation, 1in from the new bottom of the page. What I typeset there is {\rotatebox[origin=center]{90}{\thepage}}. Of course, I allow \thispagestyle{empty} so that this new page number is in lieu of the natural LaTeX page number.

\documentclass{article}
\usepackage{everypage,graphicx}
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum % Text before
\afterpage{%
    \clearpage% Flush earlier floats (otherwise order might not be correct)
    \thispagestyle{empty}% empty page style (?)
    \atxy{\dimexpr\paperwidth-1in}{.5\paperheight}{\rotatebox[origin=center]{90}{\thepage}}
    \begin{landscape}% Landscape page
        \centering % Center table
        \begin{tabular}{llll}
            A & B & C & D \\
        \end{tabular}
        \captionof{table}{Table caption}% Add 'table' caption
    \end{landscape}
    \clearpage% Flush page
}
\lipsum % Text after
\end{document}

enter image description here

  • STEVEN Thank you HOWEVER. This POC is working, but not correctly in my setup. I can place text with fixed cm, but with your parameters it does not work. QUESTION: How can output "\dimexpr\paperwidth-1in" and then converted in centimeter? I tried adding this as text but then I get the error " ! You can't use `\dimexpr' in restricted horizontal mode." – robert Aug 4 '15 at 19:28
  • @jos I am not sure I fully understand the problem. The macro \dimexpr says to convert what follows into a dimensional quantity, thus allowing primitive length additions/subtractions in a place that otherwise expects a single length spec. The process is terminated by an unexpandable \relax or, in this case, a }. You should be able to say, for example, \dimexpr\paperwidth-1cm\relax if you wanted to specify the offset from the bottom as a metric centimeter. Given a particular document style, I see nothing wrong with replacing \dimexpr\paperwidth-1in with a fixed length: xx cm. – Steven B. Segletes Aug 4 '15 at 19:35
  • @jos To print it out, \the\dimexpr..., but it will be in points. There are questions on this site for how to convert to other length units. – Steven B. Segletes Aug 4 '15 at 19:44
  • @jos Something like this: tex.stackexchange.com/questions/22701/…, but with a different conversion factor. – Steven B. Segletes Aug 4 '15 at 19:47
  • your solution is not 100% rock solid yet as it does not always work if you change margins via newgeometry. Follow up question as "answer" in this thread. – robert Aug 5 '15 at 6:35
0

The beautiful solution of Steven is not working rock solid yet. The pagenumber is falling off the page in a similar MWE (see below).

First question: why can't the PageTopMargin/PageleftMargin offsets be taken as current page margins? Why are they hardcoded?

Assume I have A4 with default margins 3.5 cm. For the landscape table I move to 1cm margins. If I follow Stevens approach, the following snippet would print the pagenumber on the right location. However it is not visible (outside page).

I can get the example below visible by changing to:

\def\PageLeftMargin{3cm}

Which is a bit strange, but then it is still not nicely aligned horizontally (driven by PageTopMargin). So I can get this working by playing around with the constants, however I am curious about a real solution.

MWE, Page Number falling off the page, what is not expected based on Steven's example.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[a4paper,top=35mm,bottom=35mm,left=35mm,right=35mm]{geometry}
\usepackage{everypage,graphicx}
\def\PageTopMargin{1cm}
\def\PageLeftMargin{1cm}
\newcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum % Text before
\afterpage{%
    \clearpage% Flush earlier floats (otherwise order might not be correct)
    \newgeometry{left=1cm, right=1cm,top=1cm,bottom=1cm}
    \thispagestyle{empty}% empty page style (?)
    \atxy{\dimexpr\paperwidth-1cm}{.5\paperheight}{\rotatebox[origin=center]{90}{\thepage}}
    \begin{landscape}% Landscape page
        \centering % Center table
        \begin{tabular}{llll}
            A & B & C & D \\
        \end{tabular}
        \captionof{table}{Table caption}% Add 'table' caption
    \end{landscape}
    \clearpage% Flush page
    \aftergroup\restoregeometry
}
\lipsum % Text after
\end{document}
  • 1
    in your example, you used geometry to set the top and left margins to 35mm. Thus, \PageTopMargin and \PageLeftMargin should likewise be set to 35mm. Things that occur at shipout (like \afterpage and \AddThispageHook) are tricky. in that some parameters from the prior page geometry are still active. My guess is the \newgeometry settings didn't make their way into the \atxy formulation, though on a subsequent page, they might. – Steven B. Segletes Aug 5 '15 at 10:42

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.