You can use the titlesec
package to change the way \paragraph
formats the titles and set the secnumdepth
counter to four to obtain numbering for the paragraphs:
\documentclass{article}
\usepackage{titlesec}
\setcounter{secnumdepth}{4}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\begin{document}
\section{Test Section}
test
\subsection{Test Subsection}
test
\subsubsection{Test Subsubsection}
test
\paragraph{Test Modified Paragraph}
test
\end{document}
If you want to define a new sectioning command, you can take a look at Defining custom sectioning commands.
If you want to define a fresh new sectional unit below \subsubsection
, but above \paragraph
, then you will have to do considerably more work: a new counter has to be created and its representation has to be appropriately defined; the sectional units \paragraph
and \subparagraph
will also have to be redefined, as well as they corresponding \l@...
commands (controlling how the will be typeset in the ToC if the tocdepth
value is increased); also, the toclevel (for eventual bookmarks) will have to be considered.
Here's an example showing how to obtain this new sectional unit giving you now the option to use \part
, \section
, \subsection
, \subsubsection
, \subsubsubsection
, \paragraph
, and \subparagraph
:
\documentclass{article}
\usepackage{titlesec}
\usepackage{hyperref}
\titleclass{\subsubsubsection}{straight}[\subsection]
\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered
\titleformat{\subsubsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
{3.25ex \@plus1ex \@minus.2ex}%
{-1em}%
{\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
{3.25ex \@plus1ex \@minus .2ex}%
{-1em}%
{\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}
\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\begin{document}
\tableofcontents
\section{Test Section}
test
\subsection{Test Subsection}
test
\subsubsection{Test Subsubsection}
test
\subsubsubsection{Test Subsubsubsection}
test
\paragraph{Test Paragraph}
test
\subparagraph{Test Subparagraph}
test
\end{document}
We must give more structure to the right mark emitted by the \chapter
command; so we do
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername\ \thechapter}
{\noexpand\firstsubsectiontitle}}
The \subsectiontitle
macro will be defined by the \subsection
command; of course it won't work if no subsection starts in the first page:
\renewcommand{\subsectionmark}[1]{%
\markright{#1}\gdef\firstsubsectiontitle{#1}}
Here's an example; notice some changes I've made to your code. For instance I've redefined the \sectionmark
command so it doesn't emit any mark.
The solution to the numbering problem of subsection is to \setcounter{secnumdepth}{1}
.
\documentclass{report}
% PACKAGES
\usepackage{fancyhdr}
\usepackage{lastpage} % Allows referencing of the last page to allow footer to read: "Page [Current page] of [Total number of pages]."
\usepackage{comment} % Allows comments of the type: \begin{comment}This text is commented out.\end{comment}
%\usepackage[colorlinks=true]{hyperref} % Turns table of contents and labels into clickable links. Commented out to speed up compiling.
\usepackage[T1]{fontenc} % Allows use of ">" symbol.
\usepackage{lmodern} %Not really sure what this is for.
% FORMATTING
% Header and Footer
\pagestyle{fancy}
% Allows calling chapter and section names in headers and footers.
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername\ \thechapter}
{\noexpand\firstsubsectiontitle}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{%
\markright{#1}\gdef\firstsubsectiontitle{#1}}
\newcommand\firstsubsectiontitle{}
% General Header and Footer
\fancyhf{}
\fancyhead[L]{\DocumentAuthor}
\fancyhead[R]{\BookAuthor>\leftmark>\rightmark}
\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}
% Chapter Header and Footer
\fancypagestyle{plain}{%
\fancyhf{} \fancyhead[L]{\DocumentAuthor}%
\fancyhead[R]{\BookAuthor>\leftmark>\rightmark}%
\fancyfoot[C]{Page \thepage\ of \pageref{LastPage}}%
}
% Header/Footer Separation-line Width
\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}
\setlength\parindent{0pt} % Remove paragraph indentation.
% NAME AND CLASS SECTION
\newcommand{\DocumentAuthor}{Author Name}
\newcommand{\BookAuthor}{Book Author}
\setcounter{secnumdepth}{1}
%DOCUMENT
\begin{document}
\tableofcontents
\thispagestyle{empty}
\chapter{Title of Chapter 1}
\section{Sample Problems}
\subsection{Title of Subsection 1}
\pagebreak{}
\subsection{Title of Subsection 2}
\subsection{Title of Subsection 3}
\pagebreak{}
\subsection{Title of Subsection 4}
\end{document}
With this code the first subsection in the page will be put in the header.
What's \noexpand\firstsubsectiontitle
doing? The \markboth
and \markright
commands must record the current values of the counters and titles, so their arguments are passed through an \edef
; this, in the case of the first chapter and English language, would set a left mark with value Chapter\ 1
. If we said only \firstsubsectiontitle
in the second argument, it would be expanded leaving a wrong right mark because it would be empty for the first chapter and would contain the last subsection in the preceding chapter!
So we say "dear TeX, don't expand \firstsubsectiontitle
right now, but only when you'll set the header."
Actually, if there can be more than one subsection in the chapter pages, a different solution should be used:
% Allows calling chapter and section names in headers and footers.
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername\ \thechapter}
{\noexpand\firstsubsectiontitle}%
\global\firstsubsectionmarktrue}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{%
\markright{#1}%
\iffirstsubsectionmark
\gdef\firstsubsectiontitle{#1}%
\fi
\global\firstsubsectionmarkfalse}
\newif\iffirstsubsectionmark
\def\firstsubsectiontitle{}
so that the first subsection would set the mark.
Best Answer
For capturing the section unit titles and have
fancyhdr
-style headings, Javier Bezos'titleps
package provides an easy alternative:Within
twoside
mode, you could usefor setting different headers/footers on even/odd pages.
You have to decide which
\subsection
to include in your headers.titleps
uses the last-defined sectional heading. However, see thetitleps
documentation for more options (section 4. Marks, p 4 onwards).