1

New on Latex world, using pdflscape package, I'm trying to create a counterclockwise landscape page (header on left and footer on right). This page has a \section for its title.

I've managed to create a new environment counterlandscape using etoolbox package and \patchcmd.

But the result is not what I've expected. The section is on the bottom right of the page instead of the upper left.

Using graphicx or rotate package, I did not managed to change it.

Here is a sample : https://www.overleaf.com/read/ctzpwwzprtsk#b3977b

\documentclass[a4paper, 11pt]{article}
\usepackage{graphicx}

\usepackage{pdflscape}

% Make landscape counter clockwise (header on left, footer on right)
\usepackage{etoolbox}
\makeatletter
\let\counterlandscape=\landscape
\let\endcounterlandscape=\endlandscape
\patchcmd{\counterlandscape}{\PLS@Rotate{90}}{\PLS@Rotate{-90}}{}{}
\makeatother

\begin{document}

\begin{counterlandscape}
    \section{Titre 1}
\end{counterlandscape}

\end{document}

I do not know if my approach is the good one or if there is a better one.

Do you know how to achieve this? My goal is to have a landscape page with header on left and footer on right with section on the upper left.

Any help would be appreciate.

Thanks

Mikk

3
  • How do you want things to look when viewed electronically vs. when printed? Because pdflscape pulls those two things apart.
    – cfr
    Oct 27, 2023 at 20:55
  • Hello @cfr, Thanks for your response. If i use landscape, header is on the right of the page and footer on the left. Section well diplayed on the upper left of the page. Because i have a large picture to display on page, which i can not change its orientation and some text is wrongly oriented, i simply want to flip landscape to display header on left and footer on the right. This document should not be printed but idealy, if it is, it would be great if it looks as electronical display. Hope i'm clear :)
    – Mikk
    Oct 30, 2023 at 7:35
  • landscape rotates the content of the page but not the header or footer. If you use pdflscape, the page is additionally rotated in the viewer, if this is supported. This does not affect how the page is printed. landscape with lscape rotates the text body anticlockwise 90 degrees. pdflscape rotates the resulting page clockwise through 90 degrees. That's all pdflscape adds to what lscape does. It doesn't touch what is on the page. It just tells the pdf viewer to turn it through 90. Since the text body is turned -90 and the page is rotated 90, the text body is orientated for reading.
    – cfr
    Oct 30, 2023 at 20:57

2 Answers 2

0

It turns out to mostly be a matter of thinking more carefully about what is being rotated by what.

We need to define not counterclockwiselandscape (or, even, anticlockwiselandscape) but clockwiselandscape. As a result, we want the PDF viewer to rotate the page anticlockwise rather than clockwise, as it typically does. I tried to figure out how to do this with pdflscape but gave up. It's a whole lot simpler to use lscape's pdftex option and patch a copy of its landscape environment, without the complications of pdflscape.

\usepackage[pdftex]{lscape}
\usepackage{etoolbox}

\makeatletter
\NewDocumentEnvironment{clockwiselandscape} {}
{%
  \def\LS@rot{\setbox\@outputbox\vbox{\hbox{\rotatebox{-90}{\box\@outputbox}}}}%

lscape defines this outside the landscape environment, but we redefine it here so regular landscape environments are not affected. For reasons I don't understand some things rotate in one direction and some in another. -90 actually rotates clockwise in this case, whereas the default 90 rotates anticlockwise.

  \@clockwiselandscape
}{%
  \end@clockwiselandscape
}
\let\@clockwiselandscape\landscape

\@clockwiselandscape is a simple copy of \landscape and does not require patching.

\let\end@clockwiselandscape\endlandscape
\patchcmd \end@clockwiselandscape {\pdfpageattr{/Rotate 90}}{\pdfpageattr{/Rotate -90}}{\typeout{Patched clockwise landscape.}}{\typeout{Failed to patch clockwise landscape!}}

This patch means the PDF viewer will be instructed to rotate the page anticlockwise rather than clockwise. Here, -90 rotates anticlockwise, whereas the original 90 rotated clockwise.

\makeatother

We can then use the clockwiselandscape environment for our content.

\begin{clockwiselandscape}
  \section{Title}
  \includegraphics{example-image}
\end{clockwiselandscape}

clockwiselandscape with anticlockwise rotation in viewer

Complete code:

\documentclass{article}
% ateb https://tex.stackexchange.com/a/700004/ i gwestiwn Mikk: https://tex.stackexchange.com/q/699688/
\usepackage[pdftex]{lscape}
\usepackage{etoolbox}

\makeatletter
\NewDocumentEnvironment{clockwiselandscape} {}
{%
  \def\LS@rot{\setbox\@outputbox\vbox{\hbox{\rotatebox{-90}{\box\@outputbox}}}}%
  \@clockwiselandscape
}{%
  \end@clockwiselandscape
}
\let\@clockwiselandscape\landscape
\let\end@clockwiselandscape\endlandscape
\patchcmd \end@clockwiselandscape {\pdfpageattr{/Rotate 90}}{\pdfpageattr{/Rotate -90}}{\typeout{Patched clockwise landscape.}}{\typeout{Failed to patch clockwise landscape!}}
\makeatother

\begin{document}
No rotation.

\begin{clockwiselandscape}
  \section{Title}
  \includegraphics{example-image}
\end{clockwiselandscape}

This shouldn't be rotated.
\end{document}

The surrounding pages are to ensure the effect is properly contained by the environment.

portrait, clockwiselandscape and portrait pages

0

Thank you @cfr for your great and complete response. And for your spent time on my problem.

I tried to use your solution (using lscape package with pdftex option) that seems the better solution but unfortunatly, this package do not work with my templates. I've spent some time to understand why but did not found and gave up.

I've finaly found a solution (not the prettiest but it works). I now patch both lscape and pdflscape commands :

\usepackage{etoolbox}
\makeatletter
% Invert lscape rotation
\patchcmd{\LS@rot}{90}{-90}{}{}
% Make landscape counter clockwise (header on left, footer on right)
\patchcmd{\landscape}{\PLS@Rotate{90}}{\PLS@Rotate{-90}}{}{}
\makeatother

This made my 'fancy' footer too high in the page so i had to change my geometry to make it fixed :

\geometry{
    ...
    top=1.2in,
    bottom=1in
    ...
}

For now, this solution fit to my needs but i'd like to understand why lscape package with pdftex option do not work with my template. Maybe some updates soon...

Again, thank you very much.

Mikk

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .