latexxelatex

How to get a \leftmark without number?


I use the following code to make a header showing current section.

\LoadClass[a4paper]{article}

\RequirePackage{titlesec} 
\titleformat{\section}{\raggedright\large\bfseries}{\,Section\,}{0em}{}
\titleformat{\subsection}[runin]{\raggedright\bfseries}{(\,\arabic{subsection}\,)}{1em}{}

\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{preContent}
{
    \fancyhf{}
    \fancyhead[L]{\leftmark}
    \renewcommand\headrulewidth{.5pt}   
}
\pagestyle{preContent}

\begin{document}
    \section{secname}
    \subsection{subname}
\end{document}

In the header it shows "1 secname". How can I get something without section number like "secname"?


Solution

  • You could redefine the \sectionmark macro:

    \LoadClass[a4paper]{article}
    
    \RequirePackage{titlesec} 
    \titleformat{\section}{\raggedright\large\bfseries}{\,Section\,}{0em}{}
    \titleformat{\subsection}[runin]{\raggedright\bfseries}{(\,\arabic{subsection}\,)}{1em}{}
    
    \RequirePackage{fancyhdr}
    \pagestyle{fancy}
    \fancypagestyle{preContent}
    {
        \fancyhf{}
        \fancyhead[L]{\leftmark}
        \renewcommand\headrulewidth{.5pt}   
    }
    \pagestyle{preContent}
    
    \renewcommand{\sectionmark}[1]{\markboth{#1}{}} 
    \begin{document}
        \section{secname}
        \subsection{subname}
    \end{document}