6

I am trying to make section headers uppercase. I tried different packages (titlesec and sectsty) but always get broken references.

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter

\usepackage{titlesec}
\titleformat{\section}%
        {\uppercase}%
        {\thesection.\enskip}%
        {0pt}%
        {}

\makeatother

\begin{document}
    \begin{equation}
        x\label{eq:x}
    \end{equation}
    \section{\ref{eq:x}}
\end{document}
7

There's no problem if you correctly use \MakeUppercase instead of \uppercase. Note also the placement.

\documentclass{article}

\usepackage{titlesec}

\titleformat{\section}
  {}
  {\thesection.\enskip}
  {0pt}
  {\MakeUppercase}

\begin{document}

\begin{equation}
x\label{eq:x}
\end{equation}

\section{A reference to \ref{eq:x}}

\end{document}

enter image description here

When babel is used, this may or may not work, depending on the definition of \sectionmark. However, loading textcase and using \MakeTextUppercase should fix the issue.

\documentclass[english]{article}
\usepackage{babel}
\usepackage{titlesec}
\usepackage{textcase}

\titleformat{\section}
  {}
  {\thesection.\enskip}
  {0pt}
  {\MakeTextUppercase}

\begin{document}

\begin{equation}
x\label{eq:x}
\end{equation}

\section{A reference to \ref{eq:x}}

\end{document}

If you also want to applying formatting to the title, here's a workaround:

\documentclass[english]{article}
\usepackage{babel}
\usepackage{titlesec}
\usepackage{textcase}

\DeclareRobustCommand{\sref}[1]{%
  \lowercase{\ref{#1}}
}

\titleformat{\section}
  {}
  {\thesection.\enskip}
  {0pt}
  {\MakeTextUppercase}

\begin{document}

\begin{equation}
x\label{eq:x}
\end{equation}

\section{A reference to \emph{\sref{eq:x}}}

\end{document}
  • Thanks for your answer. This seems to work. However, it does not work on my document. I think I have narrowed down the problem my use of \usepackage{babel} and \documentclass[english]{article}. I just can't get it to work. The references always break. Is that a bug? – Daniel Jun 25 '15 at 10:12
  • @Daniel Yes, with babel it doesn't work. I'll add a workaround for this. – egreg Jun 25 '15 at 10:19
  • Great! Thanks. That works. However, I ran into yet another problem. If the reference in the header is inside \emph{}, then it still breaks. So many riddles... – Daniel Jun 25 '15 at 10:35
  • @Daniel Sorry, but what's the purpose of having the reference in \emph? – egreg Jun 25 '15 at 10:39
  • The reference is part of a term that I want to highlight from the other text in the header. For example, "The objection to 1 and 2 implies 3". This is less ambiguous than "The objection to 1 and 2 implies 3" which could be read as "(The objection to 1) and (2 implies 3)". – Daniel Jun 25 '15 at 10:55

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.