我想要\部分标题显示在标题中,但是,如下图所示,该命令已被忽略:
我尝试了以下问题的解决方案:
MWE 是...
\documentclass[a4paper,twoside]{article}
\usepackage{titletoc}
\usepackage[pagestyles]{titlesec}
\newpagestyle{myfancy}[]{\headrule\setheadrule{0.5mm}\footrule\setfootrule{0.5mm}}
\begin{document}
\pagestyle{myfancy}
%\sethead[\thepart\:\parttitle][][\thesection\:\sectiontitle]{\thesection\:\sectiontitle}{}{\thepart\:\parttitle}
\sethead[\thepart\quad\parttitle][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{\thepart\quad\parttitle}
\setfoot[\thepage][][]{}{}{\thepage}
\part{Part A}
\section{Section AA}
\subsection{Section AA}
\subsubsection{Section AAA}
\subsubsection{Section AAB}
\subsection{Section AB}
\subsubsection{Section ABA}
\subsubsection{Section ABB}
\section{Section AB}
\end{document}
请保留标题安全解决方案中的包使用情况。
在我根据 Werner 先生的回答进行了更正并返回到我的源文件之后
我发现超链接包装并重新定义部分标题安全命令也有影响。看下面的 MWE:如果你把 放在\usepackage{hyperref}
之前,该部分将不会显示\usepackage{etoolbox}
。纠正起来很简单,但是如果你需要用 重新定义该部分标题安全命令,\parttitle
将再次消失。有什么办法吗?(请不要忘记\iffalse
从行中删除二十八使\部分标题再次消失)
\documentclass[twoside]{article}
\usepackage{titletoc,etoolbox}
\usepackage[pagestyles]{titlesec}
\newpagestyle{myfancy}[]{\headrule\setheadrule{0.5mm}\footrule\setfootrule{0.5mm}}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@part}% <cmd>
{\markboth{}{}}% <search>
{\gdef\parttitle{#1}}% <replace>
{}{}% <success><failure>
\makeatother
\usepackage{hyperref}
\pagestyle{myfancy}
%\sethead[\thepart\:\parttitle][][\thesection\:\sectiontitle]{\thesection\:\sectiontitle}{}{\thepart\:\parttitle}
\sethead[\thepart\quad\parttitle][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{\thepart\quad\parttitle}
\setfoot[\thepage][][]{}{}{\thepage}
% ---------------------
\usepackage{color,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{shadings}
\usetikzlibrary{fadings}
\iffalse
% -- Part format
\definecolor{ChapterColor}{rgb}{1.00,0.80,0.61}
\definecolor{ChapterColor2}{rgb}{0.5,0.10,0.23}
\tikzfading[name=fade up, top color=transparent!0,top color=transparent!100]
\titleformat{\part}[display]{\Large\sffamily\color{ChapterColor}}
{\filright\Huge\sffamily\bfseries \hspace*{2mm}%
\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
\node[fill=ChapterColor2,rectangle,rounded corners,text=white] {第\thepart 部};
\fill [yellow,path fading=fade up] (-2,-1) rectangle (\columnwidth-22mm,1);
\end{tikzpicture}}
{1ex}
{\titlerule[1.5pt]\huge\sffamily}
[]
\titlespacing{\part}{0pt}{0pt}{2mm}
\titleformat{name=\part,numberless}[display]
{\normalfont\color{ChapterColor}}
{}
{1ex}
{\vspace*{5ex}\huge\sffamily}
[]
\fi
\begin{document}
\part{Part A}
\section{Section AA}
\subsection{Section AA}
\subsubsection{Section AAA}
\subsubsection{Section AAB}
\subsection{Section AB}
\subsubsection{Section ABA}
\subsubsection{Section ABB}
\section{Section AB}
\newpage
\part{Part B}
\section{Section AA}
\end{document}
答案1
\part
似乎有些排他性titlesec
因此,这里有一个基本的补丁(通过etoolbox
) 将最后使用的\part
标题存储在\parttitle
:
\documentclass[twoside]{article}
\usepackage{titletoc,etoolbox}
\usepackage[pagestyles]{titlesec}
\newpagestyle{myfancy}[]{\headrule\setheadrule{0.5mm}\footrule\setfootrule{0.5mm}}
\pagestyle{myfancy}
\sethead[\thepart\quad\parttitle][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{\thepart\quad\parttitle}
\setfoot[\thepage][][]{}{}{\thepage}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@part}% <cmd>
{\markboth{}{}}% <search>
{\gdef\parttitle{#1}}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}
\part{Part A}
\section{Section AA}
\subsection{Section AA}
\subsubsection{Section AAA}
\subsubsection{Section AAB}
\subsection{Section AB}
\subsubsection{Section ABA}
\subsubsection{Section ABB}
\section{Section AB}
\end{document}
上述补丁替换\markboth{}{}
为将部件标题存储在 中\parttitle
。根据文档组成,您可能希望保留\markboth{}{}
,因此使用补丁
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@part}% <cmd>
{\markboth{}{}}% <search>
{\gdef\parttitle{#1}\markboth{}{}}% <replace>
{}{}% <success><failure>
\makeatother
删除任何与特定部分无关的标题内容。