2

I want the \parttitle displays in the header, however, as you see on the picture below, this command has been ignored:

\parttitle don't display in the header

I tried solutions from there questions:

  1. How to get part name in LaTeX ?
  2. Problems with part-labels using titlesec

The MWE is...

\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}

Please, keep the titlesec package usage in your solution.

After I corrected according Mr. Werner answer and returned to my source file

I discovered that hyperref package and redefining part with titlesec commands has influence, too. Look the MWE below: the part will not display if you place \usepackage{hyperref} before \usepackage{etoolbox}. It's simple to correct, however if you need to redefine the part with titlesec commands, \parttitle will dissapers again. Is anything possible to do with it? (Please don't forget to remove \iffalse from row 28 to make \parttitle disappear again)

\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}
2

\part seems somewhat exclusive in terms of titlesec. As such, here's a rudimentary patch (via etoolbox) that stores the last-used \part title in \parttitle:

enter image description here

\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}

The above patch exchanges \markboth{}{} for storing the part title in \parttitle. Depending on the document composition, you may want to keep the \markboth{}{} and therefore use the patch

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@part}% <cmd>
  {\markboth{}{}}% <search>
  {\gdef\parttitle{#1}\markboth{}{}}% <replace>
  {}{}% <success><failure>
\makeatother

to remove any header content not related to the specific part.

  • Don't you need to retain the \markboth{}{}? If you add a part B followed by a few pages of lipsum before the next section, you'll still get section references from part A. At least, that is what seems to happen. – cfr Oct 14 '14 at 1:24
  • @cfr: True. I've referenced this in my answer. – Werner Oct 14 '14 at 2:33
  • Dear Mr. Werner, thank you for your solution. Returned to my source document, I discovered two more factors which has influence on parttile display. If you have the time and wish to join to this reseach, please check current question field which has been updated. – Gurebu Bokofu Oct 14 '14 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.