# Is it possible to use both long name and short name of the section in headers?

I'm using fancyhdr, and following this answer I have redefined \sectionmark as:

\renewcommand{\sectionmark}[1]{\markboth{#1}{}}


so that

\fancyhead[RO,LE]{\leftmark}


gives the name of the current section in the header on the right for odd pages and left for even pages. This may sound strange, but I would additionally like the short name of the section to go on the other side of the header. So, for example, if I've declared

\section[short name]{long name}


then my pages would have headers with "short name" on one side and "long name" on the other. Can this be done? I assume that I would need to use \fancyhead[RE,LO]{\rightmark} having engineered things so that \rightmark produced the short name of the section. But I haven't had success with that. Also by providing a short name for \section[]{}, the short name is used in \leftmark instead.

(Why am I doing this? Each of these sections has a new name under a new naming convention, and an old name under an old naming convention. I am trying to cheat and use \section[]{} to declare both the new and old name, and have both appear in the header. There will be no table of contents in this document and I foresee no other use of short names.)

• If there is no toc, why not simply use \section[shortname longname]{longname}? – Johannes_B Sep 26 '14 at 7:16
• You can't use the optional argument like this. Also rightmark outputs the first mark, while leftmark the last mark so if there are two sections you would get confusing output if you use both. Better code the two names like this \section{\oldandnew{old name}{new name}}. You can then locally redefine the command \oldandnew so that it outputs either the one or the other argument. – Ulrike Fischer Sep 26 '14 at 8:17

It's ugly, but it works.

\documentclass{article}
\usepackage{everypage}
\usepackage{lipsum}

\newcommand{\shortname}{}
\newcommand{\longname}{}

\newcommand{\myhead}[2]% #1 = short name, #2 = long name
{\def\shortname{#1}%
\def\longname{#2}%
\settodepth{\headeroffset}{{#1}{#2}}% distance from baseline to bottom

\makebox[\textwidth][l]{{\shortname}\hfill{\longname}}%
\hspace{-\textwidth}\hspace{-\oddsidemargin}}% return cursor to left