Page LayoutSection Numbers and Names in Header

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
TheTobinator
Posts: 2
Joined: Wed May 22, 2013 12:04 pm

Section Numbers and Names in Header

Post by TheTobinator »

I'm new to LaTeX but I'm starting to get a hang of it but I have some problems. I would like to have section number in my header but i don't know how to do it. I'm using the fancyhdr package and writing in article class. I have seen some solutions to make this work in book settings but I like the article class better.

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[danish]{babel}
\usepackage{graphicx}
\usepackage{graphics}
\setlength{\parindent}{0in}
\usepackage{subfigure}
\usepackage{a4wide}
\usepackage{pifont}
\usepackage{float}
\parindent=0pt
\usepackage{eso-pic,fix-cm,ae,aecompl,ifthen,color}
\usepackage{fancyhdr}
\pagestyle{fancy}
%
%
%
\begin{document}
%
\fancyhead[C]{ \thesection}
\fancyhead[L]{}
\fancyhead[R]{}]
Hope someone can help!
Last edited by localghost on Wed May 22, 2013 12:13 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Section Numbers and Names in Header

Post by localghost »

Please always provide a self-contained and minimal example to give and adequate problem description that makes the problem comprehensible instantly for others.

The fancyhdr manual has lots of examples which explain what to do in this case. One of the simplest looks like this. A click on "Open in writeLaTeX" in the head of the below code box will show you the output.

Code: Select all

\documentclass[
  12pt,
  a4paper,
  danish                 % global language option for »babel«
]{article} 
\usepackage[T1]{fontenc}
\usepackage{selinput}    % semi-automatic determination ↵
\SelectInputMappings{    % of input encoding by a ↵
  ae={æ},                % list of selected glyphs ↵
  oslash={ø}             % see: http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt
}
\usepackage{babel}
\usepackage[
  margin=2cm,
  includeheadfoot,
  headheight=15pt
]{geometry}

\usepackage{fancyhdr}
\fancyhf{}
\lhead{\nouppercase{\leftmark}}
\rhead{\thepage}
\pagestyle{fancy}

\usepackage{blindtext}  % create dummy text, not for use in actual document

\begin{document}
  \blinddocument  % create dummy text, not for use in actual document
\end{document}
Thousands of possible solutions can be found by a forum search since this is FAQ. You only need to adapt them to your needs.

Furthermore there are some concerns about your code, which seems to be derived from ancient templates.
In general you should take a look at the manuals of the involved packages in your code. Or do you know from memory what eso-pic is for and what it does? Drop packages which you don't know (and therefore don't use anyway).


Best regards and welcome to the board
Thorsten
TheTobinator
Posts: 2
Joined: Wed May 22, 2013 12:04 pm

Section Numbers and Names in Header

Post by TheTobinator »

Thank you so much for your help Thorsten..

I should have been more accurate in my problem description but I thought i was doing something else wrong because I have been reading a lot in the manuel without getting anywhere..

The problem I have now is that when i run the document there are no problems but in my header it only says "contents" and nothing else. I tried calling the section with
\fancyhead[C]{ \rightmark}
Do i need to call my sections in the document something else?

\section*{Theory}
\addcontentsline{toc}{section}{Theory}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Section Numbers and Names in Header

Post by localghost »

Unnumbered sections don't get an automated entry in the header. But you can try the command \markboth or migrate your document to the corresponding article class of the KOMA-Script bundle. It is much more flexible and offers lots of options and additional packages (e.g. also one for page styles). If that doesn't help, kindly prepare a minimal example (again).
Namrod
Posts: 8
Joined: Fri Apr 26, 2013 9:10 pm

Section Numbers and Names in Header

Post by Namrod »

Here you can use the \markright command. For example :

Code: Select all

\section*{Theory}
\markright{Theory}
Post Reply