1. code listings
Using the lstlistings package, we can easily include code listings;
the following code will include a code listing from a file
and style it nicely.
% begin code listings stuff
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
% end code listings stuff
Then we can call a code listing using
\lstinputlisting[language=c]{main.c}
2. nice-looking headers and footers
The fancyhdr package lets us use nice-looking headers and footers.
You need to enable the twoside option for the odd-only and even-only headers and footers to compile properly.
You can do this by writing \documentclass[twoside]{article}.
|
% begin fancyhdr stuff
\usepackage{fancyhdr}
% Set the page style to "fancy"...
\pagestyle{fancy}
%... then configure it.
\fancyhead{} % clear all header fields
\fancyhead[RO,LE]{\textbf{The performance of new graduates}}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{From: K. Grant}
\fancyfoot[CO,RE]{To: Dean A. Smith}
% end fancyhdr stuff
2.1. but maketitle screws everything up
To remove the horizontal line above the header, use the command
\renewcommand{\headrulewidth}{0pt}.
|
3. Get last page’s number
First, import the lastpage package,
then write \pageref{LastPage} wherever you want to
include the last page of the document.