3

Why the section name is showing twice?

enter image description here

\documentclass[12pt]{report}
\usepackage{enumitem} 
\usepackage{fancyhdr} 
\pagestyle{fancy} 
\renewcommand{\sectionmark}{}
\renewcommand{\chaptermark}[1]{\markboth{}{}}
\renewcommand{\footrulewidth}{0.5pt}
\renewcommand{\headrulewidth}{0.5pt}
\fancyfoot[L]{\textit{NITK Surathkal}}
\fancyfoot[R]{\textit{Electrical Dept.}}
\fancyfoot[C]{\textit{\thepage}}
\begin{document}
\pagenumbering{arabic}
\chapter{Introduction}
Inro
\section{Objective}
The \section{Thesis Outline}
\end{document}
  • 6
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – egreg Jul 4 '16 at 14:54
  • I have more than 1000 line code. Actually I am writing a thesis for my project – Shraddha Vardikar Jul 4 '16 at 15:09
  • 1
    We can't guess, sorry. Try minimizing your code until you get a small example reproducing the issue. – egreg Jul 4 '16 at 15:09
  • 1
    @ShraddhaVardikar -- you can always edit your own question. (two people have worked on editing the code from the comment into the question, but it would not have needed to be re-flowed if you had inserted it directly.) – barbara beeton Jul 4 '16 at 15:39
  • 1
    The \renewcommand{\sectionmark}{} is wrong! – user31729 Jul 4 '16 at 15:39
3

\sectionmark is defined in the standard classes (such as report.cls) to have one argument.

Omitting it, the \section code calls \sectionmark{foo} this way:

\sectionmark%    does nothing if being defined as `\renewcommand{\sectionmark}{}`
foo

i.e. the orphaned argument foo appears in the input stream, i.e. it is typeset (in most cases, in rare cases it would be another macro that is executed)

\documentclass[12pt]{report}

\usepackage{enumitem} 
\usepackage{fancyhdr} 
\pagestyle{fancy} 

\makeatletter
\renewcommand{\sectionmark}[1]{}%
% or
%\let\sectionmark\@gobble%
\makeatother
\renewcommand{\chaptermark}[1]{\markboth{}{}}
\renewcommand{\footrulewidth}{0.5pt} 
\renewcommand{\headrulewidth}{0.5pt} 

\fancyfoot[L]{\textit{NITK Surathkal}} 
\fancyfoot[R]{\textit{Electrical Dept.}} 
\fancyfoot[C]{\textit{\thepage}} 

\begin{document} 
\pagenumbering{arabic} 
\chapter{Introduction} Intro 
\section{Objective} 
The \section{Thesis Outline} 
\end{document}

enter image description here

  • apologies for treading on your toes editing the question. – barbara beeton Jul 4 '16 at 15:44
  • @barbarabeeton: No worries – user31729 Jul 4 '16 at 15:45
0

The redefinition of \sectionmark is wrong. However, since you seem to be redefining \sectionmark and \chaptermark just to get rid of headers, there's a much simpler solution: clearing all fields before redefining them.

I added also the code for using the same style also in chapter starting pages (but omitting the top rule).

\documentclass[12pt]{report}

\usepackage{enumitem} 
\usepackage{fancyhdr} 

\pagestyle{fancy} 
\renewcommand{\footrulewidth}{0.5pt}
\renewcommand{\headrulewidth}{0.5pt}
\fancyhf{} % clear all fields
\fancyfoot[L]{\textit{NITK Surathkal}}
\fancyfoot[R]{\textit{Electrical Dept.}}
\fancyfoot[C]{\textit{\thepage}}

% add the following if you want a uniform style also
% for the chapter starting pages
\fancypagestyle{plain}
  \renewcommand{\footrulewidth}{0.5pt}%
  \renewcommand{\headrulewidth}{0pt}% no rule at the top
  \fancyhf{}% clear all fields
  \fancyfoot[L]{\textit{NITK Surathkal}}%
  \fancyfoot[R]{\textit{Electrical Dept.}}%
  \fancyfoot[C]{\textit{\thepage}}%
}

\begin{document}

\pagenumbering{arabic} 
\chapter{Introduction}
Intro

\section{Objective}

\section{Thesis Outline}

\end{document}
  • Thank you so much for your help! The h/f addition code to chapter starting pages is much appreciated :) – Shraddha Vardikar Jul 4 '16 at 21:52

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.