1

Is there a way of making a capitalized section name appear in fancyhdr as only first letters capital?

My section name is HELLO, and I want it to appear as Hello (in small capitals) in the header.

The mfirstuc package doesn't seem to give option on already capital letters, so I tried using \MakeLowercase before applying \xcapitalisewords or \capitalisewords, but it doesn't seem that simple.

Any ideas?

MWE:

\documentclass[11pt]{article}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage{mfirstuc}

\fancypagestyle{normal}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[LO]{\raisebox{-3pt}{\xcapitalisewords{\MakeLowercase\footnotesize\leftmark}}\quad\hrulefill\qquad}
\fancyhead[RO, LE]{\raisebox{-3pt}{\footnotesize\thepage}}}

\pagestyle{normal}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}\renewcommand{\subsectionmark}[1]{\markright{#1}{}}
\begin{document}
\section{HELLO}

\blindtext

\end{document}

MWE

edit 1. This is what I want.

wanted

2

\leftmark is a rather complicated command. Better change the text in the \markboth command.

\documentclass[11pt]{article}
\usepackage{fancyhdr}
\usepackage{blindtext}
\usepackage{mfirstuc}

\fancypagestyle{normal}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[LO]{\raisebox{-3pt}{\scshape\footnotesize\leftmark}\quad\hrulefill\qquad}
\fancyhead[RO, LE]{\raisebox{-3pt}{\footnotesize\thepage}}}

\pagestyle{normal}
\ExplSyntaxOn
\renewcommand{\sectionmark}[1]{\markboth{\text_titlecase:n{#1}}{}}
\ExplSyntaxOff
\renewcommand{\subsectionmark}[1]{\markright{#1}{}}
\begin{document}
\section{HELLO}

\blindtext

\end{document}

enter image description here

1
  • \exp_args:Ne\capitalisewords{\text_lowercase:n{#1}} should work. Nov 28 '20 at 18:13
1

In my opinion you should do the other way around: input the section titles normally and making them uppercase in print, so you have full control of the headers.

\documentclass[11pt,twoside]{article}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{blindtext}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {\thesection}
  {1em}
  {\MakeUppercase}

\fancypagestyle{normal}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhead[LO]{\footnotesize\leftmark\quad\xhrulefill[3pt]\qquad}%
  \fancyhead[RE]{\footnotesize\qquad\xhrulefill[3pt]\quad\rightmark}%
  \fancyhead[RO, LE]{\footnotesize\thepage}%
}

\pagestyle{normal}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}

\newcommand{\xhrulefill}[1][0pt]{%
  \leavevmode\leaders\hrule height\dimexpr0.4pt+#1\relax depth-#1 \hfill\kern0pt
}

\begin{document}

\section{Hello}

\blindtext
\blindtext
\blindtext
\blindtext

\blinddocument

\end{document}

I added code for raising the rule, which is better than lowering the other parts.

enter image description here

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.