2017-03-14 39 views
2

我們正在探索Sphinx的功能以重建我們的傳統手冊。我們已將大部分前手冊移植到Sphinx。現在我正在探索適應我們公司風格的可能性。使用Sphinx自定義Latex中的頁眉和頁腳

特別是,我們希望更改PDF手冊中頁眉和頁腳的外觀。包括公司徽標並更改偶數頁和奇數頁的外觀。

因此,我在conf.pyconf.py中加入了以下序言,並使用包fancyhdr的自定義pagestyle。

latex_elements = { 
    'preamble' : '''\ 
     \\pagestyle{fancy} 
     \\fancyhf{} 
     \\fancyhead[LE,RO]{My Header}''' 
} 

不幸的是,頭只改變begin{document}之前,之後獅身人面像樣式文件sphinx.sty莫名其妙地覆蓋我的設置。

sphinx.sty下面的代碼片段可能會導致問題:

% Redefine the 'normal' header/footer style when using "fancyhdr" package: 
\[email protected]{fancyhf}{}{ 
    % Use \pagestyle{normal} as the primary pagestyle for text. 
    \fancypagestyle{normal}{ 
    \fancyhf{} 
    \fancyfoot[LE,RO]{{\[email protected]\thepage}} 
    \fancyfoot[LO]{{\[email protected]\nouppercase{\rightmark}}} 
    \fancyfoot[RE]{{\[email protected]\nouppercase{\leftmark}}} 
    \fancyhead[LE,RO]{{\[email protected] \@title, \[email protected]}} 
    \renewcommand{\headrulewidth}{0.4pt} 
    \renewcommand{\footrulewidth}{0.4pt} 
    % define chaptermark with \@chappos when \@chappos is available for Japanese 
    \[email protected]{@chappos}{} 
     {\def\chaptermark##1{\markboth{\@chapapp\space\thechapter\space\@chappos\space ##1}{}}} 
    } 
    % Update the plain style so we get the page number & footer line, 
    % but not a chapter or section title. This is to keep the first 
    % page of a chapter and the blank page between chapters `clean.' 
    \fancypagestyle{plain}{ 
    \fancyhf{} 
    \fancyfoot[LE,RO]{{\[email protected]\thepage}} 
    \renewcommand{\headrulewidth}{0pt} 
    \renewcommand{\footrulewidth}{0.4pt} 
    } 
} 

什麼可能是一個可能的解決方法?

回答

2

內容代碼表(sphinxmanual.cls)與

\ifdefined\fancyhf\pagestyle{normal}\fi 

sphinx.sty的評論說結束了:

% Use \pagestyle{normal} as the primary pagestyle for text. 

因此最簡單的應該是你的conf.py設置覆蓋\fancypagestyle{normal},只是重新發布給你的喜好。

如果您使用\[email protected],則需要將整個膠乳包裝在\makeatletter...\makeatother中。並使用Python原始字符串來避免將所有反斜槓加倍。