自定义环境后,使用 clearpage 和 thispagestyle 的 titleps 页面样式损坏

自定义环境后,使用 clearpage 和 thispagestyle 的 titleps 页面样式损坏

titleps样式不应用cleardoublepage命令之前1.3节的最后一页样式(参见自定义\cleardoubletransition命令)。

我认为该错误与之相关,titleps因为如果您应用默认样式(例如headings),则第 1.3 节的页面样式是正确的。

请注意,将\cleardoubletransition命令放入环境中myenv可以解决问题。

如何使titleps页面样式与自定义环境保持强大功能,无论将其放在\cleardoubletransition环境的末尾还是外部?

梅威瑟:

\documentclass[12pt, a4paper, twoside]{book}

\usepackage[pagestyles,toctitles]{titlesec}
\usepackage[strict]{changepage}  % for \checkoddpage
\usepackage{lipsum}

% To clear double page and put transition
%
% USAGE
% \cleardoubletransition
%
\newcommand{\cleardoubletransition}%
{%
    \checkoddpage%
    \ifoddpage \clearpage\thispagestyle{empty}\cleardoublepage\else \cleardoublepage\fi%
}

\newpagestyle{numchapnumsec}{%
    \sethead[
        {\sffamily\normalsize\thechapter\quad\MakeUppercase{\chaptertitle}}
    ]
    []
    [
        {\sffamily\normalsize{\sectiontitle}\quad\thesection}
    ]
    {%
        {\sffamily\normalsize\thesection\quad{\sectiontitle}}
    }
    {}
    {%
        {\sffamily\normalsize\MakeUppercase{\chaptertitle}\quad\thechapter}
    }
    \setfoot*{}
    {%
        {\sffamily\thepage}
    }
    {}
}

\newenvironment{myenv}{%
    \pagestyle{numchapnumsec} % It does not work properly
    % \pagestyle{headings} % It works properly
}{}

\begin{document}


\begin{myenv}
    \chapter{Chapter 1 title}

    \section{First section first chapter}

    \lipsum[1]
    \clearpage

    \section{All is ok here}

    \lipsum[2]
    \clearpage

    \section{Bug can appear for this page!}

    \lipsum[3]

    % \cleardoubletransition % with numchapnumsec, use this instead of the next one and it works!
\end{myenv}

\cleardoubletransition % Comment it if you use the previous cleardoubletransition cmd.

\begin{myenv}
    \chapter{Chapter 2 title}

    \section{First section new chapter}

    \lipsum[4]
\end{myenv}

\end{document}

相关内容