双面文档自动旋转

双面文档自动旋转

MWE 存在问题:找到了 MWE 的解决方案。但此解决方案不适用于实际项目。到目前为止,我无法找出原因。因此,仍然欢迎其他解决方案。

我正在做一个项目,需要旋转文档中的一些图片和表格twoside。下图显示了我希望通过自动确定旋转角度实现的结果:

  • -90°在左页,
  • +90°如果反面页面没有旋转,则在正面(右侧)页面上,
  • -90°如果旋转了背面页面,则在正面页面上。

我们在此假设从左到右(LTR)的脚本(例如英语)。

我的宏\rotateRectoVerso只在前两种情况下有效。出于显而易见的原因,它在第三种情况下无法工作。解决方案必须与https://ctan.org/pkg/endfloat到目前为止,我希望保持标题不受损害,因为读者通常阅读不旋转的书,这样找到图形可能更容易。在\Ifthispageodd未定义的类中,可以比较 如果则否则奇数页/偶数页

在此处输入图片描述

\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 {\bfseries\huge J\Alph{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}

答案1

以下代码解决了 MWE 的问题,但并没有解决项目本身的问题,因为在编写 MWE 时没有预料到其他宏或包会产生一些干扰。

\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 {\bfseries\huge J\Alph{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}
\ifnum\value{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}

相关内容