TransWikia.com

Automated rotation in twoside document

TeX - LaTeX Asked on July 29, 2021

There is a problem with the MWE: A solution for the MWE was found. But this solution does not work for the actual project. So far, I could not work out the reason for this. Therefore, other solutions are still much welcomed.

I am working on a project in which I have to rotate some figures and some tables in a twoside document. The image below shows the results I want to achieve by automated determination of the rotation angles:

  • -90° on verso (left) pages,
  • +90° on recto (right) pages if the verso page is not rotated,
  • -90° on recto pages if the verso page is rotated.

We assume left-to-right (LTR) script (e.g. English language) here.

My macro rotateRectoVerso only works in the first two cases. For obvious reasons it cannot work in the third case. The solution has to work with https://ctan.org/pkg/endfloat. So far I would like to keep the captions unharmed since a reader usually reads the book unrotated and finding the figure might be easier this way.
In classes in which Ifthispageodd is not defined one might compare
If Then Else for odd page/even page.

enter image description here

documentclass[paper=b7,twoside,14pt]{scrbook}
usepackage{tikz}
% I could not solve my problem with these
%usepackage{hvfloat}
%usepackage[twoside]{rotating}

newcounter{imagecounter}
newcommand{examplePic}[1]{
stepcounter{imagecounter}
begin{tikzpicture}
    draw (-2,-2) -- (0,0) node {bfserieshuge JAlph{imagecounter}} -- (2,2);
end{tikzpicture}
}

%works in many cases
newcommand{rotateRectoVerso}[1]{Ifthispageodd{rotatebox{90}}{rotatebox{-90}}{#1}}

usepackage[nomarkers,heads,nolists,noheads]{endfloat}

begin{document}
chapter{manual}
Foo.

begin{figure}
    examplePic{}
    caption{normal}
end{figure}
begin{figure}
    rotatebox{90}{examplePic{}}
    caption{manually rotated}
end{figure}


begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}
end{figure}
begin{figure}
    examplePic{}
    caption{normal}
end{figure}




begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}
end{figure}
begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}

end{figure}


chapter{auto}
The first two pairs work (after a second compilation). The last does not. 
clearpage

begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}
begin{figure}
    examplePic{}
    caption{normal}
end{figure}


begin{figure}
    examplePic{}
    caption{normal}
end{figure}
begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}


begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}
begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}


end{document}

One Answer

The following code solves the problem for the MWE but does not solve the problem for the project itself because there is some other interference by other macros or packages which were not anticipating while the MWE was written.

documentclass[paper=b7,twoside,14pt]{scrbook}
usepackage{tikz}
% I could not solve my problem with these
%usepackage{hvfloat}
%usepackage[twoside]{rotating}

newcounter{imagecounter}

newcommand{examplePic}[1]{
stepcounter{imagecounter}
begin{tikzpicture}
    draw (-2,-2) -- (0,0) node {bfserieshuge JAlph{imagecounter}} -- (2,2);
end{tikzpicture}
}

newcounter{lastRotatedVerso}setcounter{lastRotatedVerso}{-99}
newcounter{lastRotatedVersoStep}setcounter{lastRotatedVerso}{-95}

newcommand{rotateRectoVerso}[1]{Ifthispageodd
{%Recto
% A second counter might be necessary if two floats on the recto need to be rotated
setcounter{lastRotatedVersoStep}{value{lastRotatedVerso}}
stepcounter{lastRotatedVersoStep}
ifnumvalue{lastRotatedVersoStep}=value{page}
rotatebox{-90}{#1}
else
rotatebox{90}{#1}
fi
}{%Verso
rotatebox{-90}{#1}
setcounter{lastRotatedVerso}{thepage}
}
}


usepackage[nomarkers,heads,nolists,noheads]{endfloat}

begin{document}
chapter{manual}
Foo.

begin{figure}
    examplePic{}
    caption{normal}
end{figure}
begin{figure}
    rotatebox{90}{examplePic{}}
    caption{manually rotated}
end{figure}


begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}
end{figure}
begin{figure}
    examplePic{}
    caption{normal}
end{figure}




begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}
end{figure}
begin{figure}
    rotatebox{-90}{examplePic{}}
    caption{manually rotated}

end{figure}


chapter{auto}
The first two pairs work (after a second compilation). The last does not. 
clearpage

begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}
begin{figure}
    examplePic{}
    caption{normal}
end{figure}


begin{figure}
    examplePic{}
    caption{normal}
end{figure}
begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}


begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}
begin{figure}
    rotateRectoVerso{examplePic{}}
    caption{automatically rotated}
end{figure}



end{document}

Correct answer by CampanIgnis on July 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP