奇数页和偶数页的底部边距不同

奇数页和偶数页的底部边距不同

我正在尝试制作具有以下要求的文章类文档:

  • 两边
  • 除章节和小节标题外,还有两列多列
  • 页眉、页脚和章节标题根据章节编号着色

我做到了,但不幸的是,底部边距出现了奇怪的行为。边距在偶数页或奇数页上都会发生变化。我完全不知道如何解决这个问题……这是我遇到问题的代码。

\documentclass[12pt,twoside,english]{article}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{ifthen}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[framemethod=TikZ]{mdframed}

\usepackage{tikz}
\usepackage{xcolor}
%\usepackage{libertine}
%\usepackage[bottom]{footmisc}
\usepackage{geometry}
\geometry{verbose,
top=1cm,
bottom=1.8cm,
left=2.2cm,
right=2.2cm}

\usepackage{setspace}
%%Define a color for each section
\definecolor{zz0}{rgb}{.1,.8,.3}
\definecolor{zz1}{rgb}{.8,.2,.2}
\definecolor{zz2}{rgb}{.7,.9,.1}
\definecolor{zz3}{rgb}{.6,.4, 0}
\definecolor{zz4}{rgb}{.5,.1,.9}
\definecolor{zz5}{rgb}{.1, 0,.8}
\definecolor{zz6}{rgb}{.7,.2,.6}
\definecolor{zz7}{rgb}{.9,.3,.8}
\definecolor{zz8}{rgb}{0 ,.4,.1}
\definecolor{zz9}{rgb}{.7,.5,.2}
\definecolor{zz10}{rgb}{.1,.6,.3}
\definecolor{zz11}{rgb}{.6,.8,.5}

\renewcommand*{\hrulefill}[2][0pt]{\leavevmode \leaders \hbox to 1pt{\rule[#1]{1pt}{#2}} \hfill \kern 0pt} 

% For headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}%
\renewcommand{\headrulewidth}{1pt}% 2pt header rule
\renewcommand{\headrule}{\hbox to\headwidth{%
    \color{zz\arabic{section}}\leaders\hrule height \headrulewidth\hfill}}
\fancyhead[LE,RO]{\raisebox{-.9\baselineskip}[0pt][0pt]{\textsc{\textsf{\leftmark}}}}
\fancyfoot[RO]{ \color{zz\arabic{section}} \hrulefill{6pt} \normalcolor \,
some random text %
\color{zz\arabic{section}} \rule{10pt}{6pt} \normalcolor \thepage}%
\fancyfoot[LE]{\thepage \, \color{zz\arabic{section}} \rule{10pt}{6pt} \normalcolor%
Some random text %
\color{zz\arabic{section}} \hrulefill{6pt}}


\renewcommand{\sectionmark}[1]{\markboth{\color{zz\arabic{section}}#1}{}}
%% Create if environment
\makeatletter
\def\ifenv#1{
   \def\@tempa{#1}%
   \ifx\@tempa\@currenvir
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
   \fi
}
\makeatother

%% Redefine the section
\usepackage{titlesec}

\let\oldsection\section
\renewcommand{\section}[1]{%
    \ifenv{multicols}{\end{multicols}\clearpage}{\clearpage}%
    \begin{multicols}{2}[\oldsection{#1}]}
%% Redefine the end of the document
\let\oldend\enddocument
\renewcommand*{\enddocument}{\ifenv{multicols}{\end{multicols}}{}\oldend}
%% Redefine the subsection
\let\oldsubsection\subsection
\renewcommand{\subsection}[1]{%
   \ifenv{multicols}{\end{multicols}}{}%
   \begin{multicols}{2}[\oldsubsection{#1}]}

\titleformat{\section}{\LARGE\normalfont\color{zz\arabic{section}}}{\thesection}{1em}{}
\titleformat{\subsection}{\Large\normalfont\color{zz\arabic{section}}}{\thesubsection}{1em}{}


\begin{document}

\section{Section}
\lipsum[1-2]
\subsection{Subsection}
\blindtext[4]

\section{Section}
\blindtext[2]
\subsection{Subsection}
\blindtext[2]

\section{Section}
\blindtext[2]
\subsection{Subsection}
\blindtext[2]

\section{Section}
\subsection{Subsection}
\blindtext[2]

\section{Section}
\subsection{Subsection}
\blindtext[2]


\end{document}

感谢您的帮助

答案1

问题出在 的使用上fancyhdr。我不知道它到底出了什么问题,但它无法将页脚设置在一致的高度。因此,我使用 重新创建了您的整体外观scrlayer-scrpage。(我希望我一切都正确)

我做了一些其他更改,主要是代码格式。我还删除了 的重新定义,\enddocument而改用。\AtEndDocument我还使用了和。如果您\LetLtxMacro将来使用可选参数重新定义或 ,这将很重要。\let\section\subsection\section\subsection

代码:

\documentclass[12pt,twoside,english]{article}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{multicol}
\usepackage{lipsum}

\usepackage{xcolor}
\usepackage{libertine}
\usepackage{geometry}
\geometry
  {%
    verbose
    ,top=1cm
    ,bottom=1.8cm
    ,left=2.2cm
    ,right=2.2cm
    ,headsep=4mm % control the height of the header (the bigger the higher)
    ,headheight=15pt
  }

%%Define a color for each section
\definecolor{zz0}{rgb}{.1,.8,.3}
\definecolor{zz1}{rgb}{.8,.2,.2}
\definecolor{zz2}{rgb}{.7,.9,.1}
\definecolor{zz3}{rgb}{.6,.4, 0}
\definecolor{zz4}{rgb}{.5,.1,.9}
\definecolor{zz5}{rgb}{.1, 0,.8}
\definecolor{zz6}{rgb}{.7,.2,.6}
\definecolor{zz7}{rgb}{.9,.3,.8}
\definecolor{zz8}{rgb}{0 ,.4,.1}
\definecolor{zz9}{rgb}{.7,.5,.2}
\definecolor{zz10}{rgb}{.1,.6,.3}
\definecolor{zz11}{rgb}{.6,.8,.5}

\renewcommand*\hrulefill[2][0pt]
  {%
    \leavevmode \leaders \hbox to 1pt{\rule[#1]{1pt}{#2}}\hfill \kern 0pt
  }

\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\raisebox{-.2\baselineskip}[0pt][0pt]{\leftmark}}
\rofoot
  {%
    \color{zz\arabic{section}}%
    \hrulefill{6pt}%
    \normalcolor
    \, Some random text
    \color{zz\arabic{section}}%
    \rule{10pt}{6pt}
    \normalcolor
    \pagemark
  }
\lefoot
  {%
    \pagemark
    \,
    \color{zz\arabic{section}}%
    \rule{10pt}{6pt}%
    \normalcolor
    \ Some random text
    \color{zz\arabic{section}}%
    \hrulefill{6pt}%
  }
% For headers
\KOMAoption{headsepline}{1pt} % rule thickness
\setkomafont{headsepline}{\color{zz\arabic{section}}} % rule colour
\setkomafont{pagehead}{\color{zz\arabic{section}}\normalfont\sffamily\scshape}
\setkomafont{pagefoot}{\normalfont}

\renewcommand\sectionmark[1]
  {%
    \markboth{\color{zz\arabic{section}}#1}{}%
  }
%% Create if environment
\makeatletter
\def\ifenv#1%
  {%
    \def\@tempa{#1}%
    \ifx\@tempa\@currenvir
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }
\makeatother

%% Redefine the section
\usepackage{titlesec}
\usepackage{letltxmacro}
\titleformat{\section}
  {%
    \LARGE\normalfont\color{zz\arabic{section}}%
  }
  {\thesection}{1em}{}
\titleformat{\subsection}
  {%
    \Large\normalfont\color{zz\arabic{section}}%
  }
  {\thesubsection}{1em}{}

%% Redefine the end of the document
\AtEndDocument{\ifenv{multicols}{\end{multicols}}{}}
%% Redefine the section
\LetLtxMacro\oldsection\section
\renewcommand\section[1]
  {%
    \ifenv{multicols}{\end{multicols}}{}%
    \clearpage
    \begin{multicols}{2}[\oldsection{#1}]%
  }
%% Redefine the subsection
\LetLtxMacro\oldsubsection\subsection
\renewcommand\subsection[1]
  {%
    \ifenv{multicols}{\end{multicols}}{}%
    \begin{multicols}{2}[\oldsubsection{#1}]%
  }



\begin{document}

\section{Section}
\lipsum[1-2]
\subsection{Subsection}
\blindtext[4]

\section{Section}
\blindtext[2]
\subsection{Subsection}
\blindtext[2]

\section{Section}
\blindtext[2]
\subsection{Subsection}
\blindtext[2]

\section{Section}
\subsection{Subsection}
\blindtext[2]

\section{Section}
\subsection{Subsection}
\blindtext[2]


\end{document}

在此处输入图片描述

相关内容