5

I would like to create a newcounter (lectcount) which will be one level above the "section" in article class, and use its name in the headings (I am using fancyhdr). I don't know how to set the hierarchy level above section, and also I don't know how to refer to its name in order to write it in the page headings.

I have come out with the following code. The end of \lecture definition was supposed to capture the lecture's name argument, which doesn't work. Any help will be appreciated.

\newcounter{lectcount}
\newcommand{\lecture}[1]{\refstepcounter{lectcount}%
    \noindent\textbf{\LARGE Lecture \thelectcount: #1}\par\bigskip%
    \let\lectname\#1}

\fancyhead[L]{Lecture \thelectcount: \lectname}

\begin{document}
\lecture{My First Lecture}
...
\end{document}
6
  • 5
    Why don't you just use a chapter based class (like »report«) and rename "Chapter" to "Lecture"? Commented Oct 9, 2011 at 8:50
  • Why would that be easier than editing "Part"?
    – PineApple
    Commented Oct 9, 2011 at 10:01
  • Because you only need to insert \renewcommand{\chaptername}{Lecture} into your preamble. Commented Oct 9, 2011 at 10:05
  • But as I wanted with the part sectioning, I want to enter its name in the header, and also edit it's font. So it's not just changing the name
    – PineApple
    Commented Oct 9, 2011 at 10:22
  • Could all be done easily by the titlesec package. Commented Oct 9, 2011 at 11:07

1 Answer 1

7

The easiest way is to use the report or book class and their \chapter command.

However, also the article class provides \part, that you can use above \section.

\documentclass[a4paper]{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\def\lecturemark{}
\fancyhf{}
\fancyhead[L]{\lecturemark}
\fancyfoot[C]{\thepage}

\newcommand{\lecture}[1]{\part{#1}\def\lecturemark{\partname\ \thepart: #1}}
\renewcommand{\partname}{Lecture}

% Let's customize \part
\usepackage{etoolbox}% for \patchcmd
\renewcommand{\thepart}{\arabic{part}}
\makeatletter
\patchcmd{\@part}{\par\nobreak}{: }{}{}
\patchcmd{\@part}{\huge}{\Large}{}{}
\makeatother

\usepackage{lipsum}

\begin{document}
\lecture{How to write lectures}
\section{First step: how to copy}
\lipsum
\end{document}

For more extensive changes to the appearance of the lecture title, copy in your document the definition of \@part in article.cls and modify that directly.

3
  • Thanks. btw is your first definition \def\lecturemark{} really necessary? it worked for me without it. and how do I override the fonts of the part sectioning? for example if I want the \part (and therefore the \lecture) to write **Lecture 1: How to write lecture ** in the same fontsize, unlike the part defaults.
    – PineApple
    Commented Oct 9, 2011 at 10:43
  • I see. Thanks again! and just out of curiousity, Why is editing the "Chapter" in book class easier than the "Part" in article, isn't it the same principle? and also, is it complicated to define a new counter and then fit it inside the hierarchy of the section, subsection etc.? (for example, if I want to use all sectioning commands, including "part".) Edit: you defined the font of the Lecture to be large. How do I change both the font name "Lecture 1", and it's name "My Lecture", to huge?
    – PineApple
    Commented Oct 9, 2011 at 10:44
  • @PineApple Just switch: \patchcmd{\@part}{\Large}{\huge}{}{}
    – egreg
    Commented Oct 9, 2011 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .