自定义 \part 的问题

自定义 \part 的问题

我使用 titlesec 包来设置部件样式,但我还想将部件的名称放在标题中。我尝试了此线程中提出的方法(如何在 LaTeX 中获取零件名称?)。我得到了我想要的标题,但它导致我的文档中的部分名称重复(见下文)...

截屏

以下是部分代码:

\titleformat{\part}[display]%
    {\Huge\sffamily\bfseries}%
    {\filleft{\huge\sffamily \textbf{\partname \\}}}%
    {0mm}%
    {\thispagestyle{empty}\filleft}%
    []%
\titlespacing{\part}{0mm}{40pt}{40pt}[- \marginparwidth - \marginparsep]%

\let\letpart\part
\renewcommand{\partmark}{}
\renewcommand{\part}[2][]{% 
   \ifx\\#1\\
      \letpart{#2}%
      \renewcommand\partmark{\partname{} -- #2}%
   \else
      \letpart[#1]{#2}%
      \renewcommand\partmark{\partname{} -- #1}%
   \fi
}

如果我仅使用,我也会遇到同样的问题:

\let\letpart\part
\renewcommand{\part}[1]{\letpart{#1}}

(所以问题似乎出在使用 \let 时)。有人有办法避免这种情况吗?谢谢您的帮助。

编辑:这是可编译的代码。这是我制作的一个类的一部分;我列出了整个包列表,以防您发现冲突。

\documentclass[twoside, openright]{report}

\usepackage[paper=a4paper, lmargin=15mm, rmargin=15mm, tmargin=15mm, bmargin=15mm,
                        includeall, marginparwidth=44mm, headheight=\baselineskip]{geometry}
\usepackage[francais]{babel}
\usepackage[latin1]{inputenc}

\usepackage[fleqn]{amsmath}
\usepackage{amssymb, mathrsfs, stmaryrd, gensymb}
\usepackage[upright]{fourier}
\usepackage{emerald}

\usepackage{setspace}
\usepackage{calc}
\usepackage{array, multirow, tabularx}
\usepackage{xcolor, color, colortbl}
\usepackage{graphicx, picins}
\usepackage{subfig}
\usepackage[top]{mcaption}
\usepackage{fancyhdr, lastpage}
\usepackage[fit]{truncate}
\usepackage{mdwlist}
\usepackage{titlesec, titletoc}
\usepackage{ulem}
\usepackage{float}
\usepackage[globalcitecopy]{bibunits}
\usepackage{multido}
\usepackage{ragged2e}
\usepackage{marginfix}

\usepackage[geometry]{ifsym}
\usepackage{ifthen}
\usepackage[strict]{changepage}
\usepackage{framed}


\makeatletter
\definecolor{abricot1}{rgb}{1,0.580,0.412}
\definecolor{abricot2}{rgb}{1,0.680,0.565}
\definecolor{abricot3}{rgb}{1,0.933,0.890}

\newcommand{\couleurP}[0]{abricot1}%
\newcommand{\couleurS}[0]{abricot2}%
\newcommand{\couleurT}[0]{abricot3}%

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyheadoffset[RO,LE]{\marginparsep + \marginparwidth}

\fancyhf{}
\fancyhead[LE]{\small\textsf{\thepage} \quad%
    \textcolor{\couleurP}{$\blacksquare\thinspace$}\textcolor{\couleurS}{$\blacksquare\thinspace\blacksquare$}}
\fancyhead[RO]{\textcolor{\couleurS}{$\blacksquare\thinspace\blacksquare$}\textcolor{\couleurP}{$\thinspace\blacksquare$} \quad%
    \small\textsf{\thepage}}
\fancyfoot{}

\titleformat{\part}[display]%
        {\Huge\sffamily\bfseries}%
        {\filleft{\huge\sffamily \textbf{\partname \\}}}%
        {0mm}%
        {\thispagestyle{empty}\filleft}%
        []%
    \titlespacing{\part}{0mm}{40pt}{40pt}[- \marginparwidth - \marginparsep]%

\let\letpart\part
\renewcommand{\partmark}{}
\renewcommand{\part}[2][]{%
   \ifx\\#1\\
      \letpart{#2}%
      \renewcommand\partmark{\partname{} -- #2}%
   \else
      \letpart[#1]{#2}%
      \renewcommand\partmark{\partname{} -- #1}%
   \fi
}
\makeatother


\title{{\'E}tude expérimentale...}

\fancyhead[RE]{\small\textsf{\truncate{120mm}{\nouppercase{\leftmark}}}}
\fancyhead[LO]{\small\textsf{\truncate{120mm}{{\'E}tude expérimentale...}}}

\pagestyle{empty}

\author{Emmanuel G.}

\date{\today}


\begin{document}

\pagestyle{fancy}

\maketitle

\part{Du microscopique au mésoscopique}
\fancyhead[LO]{\small\textsf{\truncate{120mm}{\partmark}}}
tba.


\end{document}

答案1

命令\...mark应该使用\markboth\markright设置\leftmark\rightmark,仅可在中使用\fancyhead

\documentclass[twoside, openright]{report}

\usepackage[paper=a4paper, lmargin=15mm, rmargin=15mm, tmargin=15mm, bmargin=15mm,
                        includeall, marginparwidth=44mm, headheight=\baselineskip]{geometry}


\usepackage[francais]{babel}
\usepackage[utf8]{inputenc} % just for me!

\usepackage[fleqn]{amsmath}
\usepackage{amssymb, mathrsfs, stmaryrd, gensymb}
\usepackage[upright]{fourier}
%\usepackage{emerald} % I have no emerald package

\usepackage{setspace}
\usepackage{calc}
\usepackage{array, multirow, tabularx}
\usepackage{xcolor, color, colortbl}
\usepackage{graphicx}
%\usepackage{picins} % I have no picins package
\usepackage{subfig}
\usepackage[top]{mcaption}
\usepackage{fancyhdr, lastpage}
\usepackage[fit]{truncate}
\usepackage{mdwlist}
\usepackage{titlesec, titletoc}
\usepackage{ulem}
\usepackage{float}
\usepackage[globalcitecopy]{bibunits}
\usepackage{multido}
\usepackage{ragged2e}
\usepackage{marginfix}

\usepackage[geometry]{ifsym}
\usepackage{ifthen}
\usepackage[strict]{changepage}
\usepackage{framed}

\usepackage{kantlipsum} % just to fill up pages with nonsense


\makeatletter
\definecolor{abricot1}{rgb}{1,0.580,0.412}
\definecolor{abricot2}{rgb}{1,0.680,0.565}
\definecolor{abricot3}{rgb}{1,0.933,0.890}

\newcommand{\couleurP}[0]{abricot1}%
\newcommand{\couleurS}[0]{abricot2}%
\newcommand{\couleurT}[0]{abricot3}%

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyheadoffset[RO,LE]{\marginparsep + \marginparwidth}

\fancyhf{}
\fancyhead[LE]{%
  \small\textsf{\thepage}\quad
  \textcolor{\couleurP}{$\blacksquare\thinspace$}%
  \textcolor{\couleurS}{$\blacksquare\thinspace\blacksquare$}%
}
\fancyhead[RO]{%
  \textcolor{\couleurS}{$\blacksquare\thinspace\blacksquare$}%
  \textcolor{\couleurP}{$\thinspace\blacksquare$}%
  \quad\small\textsf{\thepage}%
}
\fancyfoot{}

\titleformat{\part}[display]%
        {\Huge\sffamily\bfseries}%
        {\filleft{\huge\sffamily \textbf{\partname \\}}}%
        {0mm}%
        {\thispagestyle{empty}\filleft}%
        []%
    \titlespacing{\part}{0mm}{40pt}{40pt}[- \marginparwidth - \marginparsep]%

\renewcommand{\chaptermark}[1]{\markright{\thechapter.\ \ #1}}
\renewcommand{\partmark}[1]{\markboth{\thepart.\ \ #1}{}}

\makeatother


\title{{\'E}tude expérimentale...}

\pagestyle{empty}

\author{Emmanuel G.}

\date{\today}


\begin{document}

\pagestyle{fancy}

\maketitle

\part{Du microscopique au mésoscopique}
\fancyhead[LO]{\small\textsf{\truncate{120mm}{\leftmark}}}
\fancyhead[RE]{\small\textsf{\truncate{120mm}{\rightmark}}}

\chapter{Je ne sais pas}

\kant[1-12]


\end{document}

奇数页顶部

在此处输入图片描述

偶数页顶部

在此处输入图片描述

答案2

解决方案没有fancyhdr,我用 代替了titleps,因为你使用titlesec。你不必设置标记,只需设置\chaptertitle\parttitle命令。

我删除了与问题无关的软件包,字体加载除外。请注意,color由于您加载了 ,因此加载毫无意义xcolor。此外,您应该inputenc使用选项加载utf8,因为它更易于移植:如今所有平台和所有现代编辑器都理解 utf8。

\documentclass[twoside, openright]{report}

\usepackage[paper=a4paper, lmargin=15mm, rmargin=15mm, tmargin=15mm, bmargin=15mm,
                        includeall, marginparwidth=44mm, headheight=\baselineskip]{geometry}
\usepackage[francais]{babel}
\usepackage[utf8]{inputenc}

\usepackage[fleqn]{amsmath}
\usepackage{amssymb, mathrsfs, stmaryrd, gensymb}
\usepackage[upright]{fourier}

\usepackage{calc}
\usepackage{xcolor, colortbl}%
\usepackage[clearempty, toctitles, newparttoc, pagestyles]{titlesec}

\usepackage{lipsum}

\definecolor{abricot1}{rgb}{1,0.580,0.412}
\definecolor{abricot2}{rgb}{1,0.680,0.565}
\definecolor{abricot3}{rgb}{1,0.933,0.890}

\newcommand{\couleurP}[0]{abricot1}%
\newcommand{\couleurS}[0]{abricot2}%
\newcommand{\couleurT}[0]{abricot3}%

\newpagestyle{mystyle}{%
\settitlemarks{part, chapter}
\widenhead[\marginparsep + \marginparwidth][0pt]{0pt}{\marginparsep + \marginparwidth}
\sethead[\small\textsf{\thepage} \quad \textcolor{\couleurP}{$\blacksquare\thinspace$} \textcolor{\couleurS}{$\blacksquare\thinspace\blacksquare$}][][\thechapter. \enspace \chaptertitle]{\partname\enspace–\enspace\parttitle}{}{\textcolor{\couleurS}{$\blacksquare\thinspace \blacksquare$}\textcolor{\couleurP}{$\thinspace\blacksquare$} \quad \small\textsf{\thepage}}
    }%


\titleformat{\part}[display]%
        {\Huge\sffamily\bfseries}%
        {\filleft{\huge\sffamily \textbf{\partname \\}}}%
        {0mm}%
        {\thispagestyle{empty}\filleft}%
        []%
    \titlespacing{\part}{0mm}{40pt}{40pt}[- \marginparwidth - \marginparsep]%

\title{Étude expérimentale...}

\author{Emmanuel G.}

\date{\today}

\pagestyle{empty}

\begin{document}

\maketitle

\pagestyle{mystyle}

\part{Du microscopique au mésoscopique}

 \chapter{Le microscopique}
\lipsum[1-20]

\end{document} 

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

相关内容