0

How can I set different header for different sections. In this example I am looking for replacement of \SomeCommand

\documentclass{article}
\begin{document}

\SomeCommand{Header 1 define here} %this sets header for all pages until another \SomeCommand found

This is multi-page text
\newpage

\SomeCommand{Header 2 define here} %this changes the header to new 

This is multi-page text
\end{document}

My document is NOT arranged in \section and not a book. It is just plane text.

  • Did you try creating different page styles and using them locally? – Bernard Jun 2 '15 at 20:03
  • 2
    if your document already has running heads (which article usually does), then they can be changed by specifying \markboth{text}{text} on the page on which the change is first wanted. – barbara beeton Jun 2 '15 at 20:39
2

If there are no special layout requirements you can use the pagestyle myheadings. Then \SomeCommand has to set \markright{<text>} or maybe better \markboth{<text>}{<text>}. The second works also if your document is twoside.

\documentclass{article}
\pagestyle{myheadings}
\newcommand*\SomeCommand[1]{\markboth{#1}{#1}}

\usepackage{lipsum}% dummy text
\begin{document}
\SomeCommand{Header 1 define here}
\lipsum
\clearpage
\SomeCommand{Header 2 define here}
\lipsum
\end{document}
2

I think, this is available by using the fancy pagestyle and setting the page headers at will, by using the wrapper command \SomeCommand

\documentclass[twoside]{article}

\usepackage{blindtext}

\usepackage{fancyhdr}
\fancyhead[LE,RO]{\thepage}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{2pt}

\newcommand{\SomeCommand}[1]{%
  {\noindent\LARGE \textbf{#1}\vskip 2\baselineskip}
  \fancyhead[CE,CO]{#1}
}
\pagestyle{fancy}
\begin{document}


\SomeCommand{The Theory on Brontosaurs} %this sets header for all pages until another \SomeCommand found
\blindtext[20]
\newpage

\SomeCommand{The extended Theory on Brontosaurs} %this changes the header to new 

\blindtext[20]
\end{document}

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.