Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want the header to be empty in the page were section begins and showed in the other pages. How can I do that?

\documentclass[12pt, titlepage, onecolumn, a4paper]{article}

\usepackage{lipsum}    %% for dummy text

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark
\fancyhf{}

\lhead{\leftmark}
\chead{}
\rhead{\rightmark}
\cfoot{\footnotesize\selectfont\bfseries\thepage}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\setlength{\headheight}{8pt}

\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}

\begin{document}
\lipsum[1]
  \pagenumbering{roman}
  \setcounter{page}{2}
\lipsum[1]
  \rhead{\footnotesize{\thesection{ } \leftmark}}
  \pagenumbering{arabic}
  \setcounter{page}{1}
\section{First Section}
\lipsum[2-5]
\section{Second Section}
\lipsum[2-8]
\end{document}
share|improve this question

3 Answers 3

up vote 3 down vote accepted

I'm not sure what do you mean by empty but if you are looking for the normal layout without the text of the header you can add this pagestyle to your preamble:

\fancypagestyle{FooBar}{%
    \fancyhead{}
    \renewcommand{\headrulewidth}{1pt}
}

and then start your sections by declaring

\section{Second Section}\thispagestyle{FooBar}

This will give you

enter image description here

If you literally need an empty layout, you can use \thispagestyle{empty} as it is already defined by the package (an other predefined style is plain).

share|improve this answer
    
it was the FooBar solution what I was looking for. Thank you very much! –  Kaiser Schwarcz Jul 3 '14 at 14:07

You can make the choice automatic, by adding some code to \section

\documentclass[12pt, titlepage, onecolumn, a4paper]{article}
\usepackage{fancyhdr}
\usepackage{chngcntr}
\usepackage{xparse}

\usepackage{lipsum}    %% for dummy text

\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark
\fancyhf{}
\fancyhead[L]{\leftmark}
\fancyfoot[C]{\footnotesize\bfseries\thepage}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\setlength{\headheight}{14.5pt} % <-------- 8pt is too small!

\fancypagestyle{section}{%
  \fancyhf{}%
  \fancyfoot[C]{\footnotesize\bfseries\thepage}
  \renewcommand{\headrulewidth}{0.4pt}%
  \renewcommand{\footrulewidth}{0.4pt}%
}


\counterwithin{figure}{section}
\counterwithin{table}{section}

% the starting page of a section will not have a header
\let\originalsection\section
\RenewDocumentCommand{\section}{som}{%
  \IfBooleanTF{#1}
    {\originalsection*{#3}}
    {\IfNoValueTF{#2}
      {\originalsection{#3}}
      {\originalsection[#2]{#3}}%
    }%
  \thispagestyle{section}%
}

\begin{document}
\lipsum[1]
\lipsum[1]
\section{First Section}
\lipsum[2-5]
\section{Second Section}
\lipsum[2-8]
\end{document}

I added also the correct size for \headheight (unless you use a smaller font 14.5pt is necessary). Also I removed the setting of \rightmark, add it if really wanted, but then you probably have to redefine \subsectionmark.

Also I defined the counters for tables and figures using chngcntr and \counterwithin; this way the counters will be reset at each section.

share|improve this answer

It can also be achieved if you define the \fancypagestyle, as Pouya did:

\fancypagestyle{FooBar}{% 
   \fancyhead{}
   \renewcommand{\headrulewidth}{1pt}
}

and somewhere in the preamble (before \begin{document}) state:

\let \OldSection \section
\renewcommand{\section}[1]{\OldSection{#1} \thispagestyle{FooBar}}

:: Update ::

In my case, sometimes, I want to open a section on a new page, using memoir. So, I use the following tex:

\documentclass[12pt,twoside,a4paper]{memoir}

\usepackage{lipsum}    %% for dummy text

\let\footruleskip\undefined
\usepackage{fancyhdr}

% Apply section style
\let \OldSection \section
\renewcommand{\section}[1]{\OldSection{#1} \thispagestyle{plainsec}}


% Define your page styles
\pagestyle{fancy}               
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername
\ \thechapter\ - #1}{}}
\renewcommand{\sectionmark}[1]{%
            \markright{\thesection\ - #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt}

\fancypagestyle{plain}{  %chapter openning
        \fancyhf{}
        \fancyhead[RO]{\bfseries\thepage}
        \renewcommand{\headrulewidth}{0pt}
}
\fancypagestyle{plainsec}{  %section openning
        \fancyhf{}
        \fancyhead[RO]{\bfseries\thepage}
        \renewcommand{\headrulewidth}{0pt}
}


\begin{document}
\chapter{First Chapter}
\lipsum[1]
\section{A Section after some text}
\lipsum[2-5]
\subsection{A Sub-section}
\lipsum[2-5]

\cleardoublepage
\section{A Section at a new page}
\lipsum[2-8]
\end{document}
share|improve this answer
    
Please elaborate on this and show a screen shot, for example –  Christian Hupfer Dec 30 '14 at 13:10
    
I add an example above. If you want, you can define a specific section command, whenever you need a section opening like a chapter usually does. –  tasilva Dec 31 '14 at 0:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.