# setting header inside document for some pages

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? Jun 2 '15 at 20:03
• 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. Jun 2 '15 at 20:39

## 2 Answers

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}


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}