I've set some formatting in my table of contents, list of tables, and list of figures that I want to continue in my list of listings (using tocloft
package). However, I can't find the commands to do so. Consider the following example:
\documentclass[12pt,letterpaper,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{letterpaper,left=1.25in,top=1in,right=1in,bottom=1in,nohead}
\usepackage{listings}
\renewcommand{\lstlistingname}{Code} %change 'listing' to 'code'
%
%
\begin{document}
%
%Adjusted the font of the list of listings title
\renewcommand{\lstlistlistingname}{\centering\bfseries\normalsize{LIST OF CODE}}
%
\lstlistoflistings
\vspace{1in}
%
%test listings
\begin{lstlisting}
test code
\end{lstlisting}
\begin{lstlisting}
test code 2
\end{lstlisting}
%
\end{document}
I want to do a few things.
1) I want to control the distance from the top margin to the LIST OF CODE title similar to \setlength{\cftbeforetoctitleskip}{1in}
in tocloft
. Is there a way to do this with the listings package?
Update: This distance is controlled by tocloft
. Thus, use \setlength{\cftbeforetoctitleskip}{\spaceBeforeChapterTitles}
.
2) I want to control the vskip between the LIST OF CODE title and the first line similar to \setlength{\cftaftertoctitleskip}{12pt}
in tocloft
.
Update: This distance is controlled by tocloft
as well. Thus, use
\setlength{\cftaftertoctitleskip}{\spaceBetweenTitleAndText}
.
3) I want to control the vskip values in between the list of listings entries (i.e. 12pt skip between exlist and exlist2 lines) like I do with \setlength{\cftbeforechapskip}{12pt}
in tocloft
.
4) I want to control the space between dots, similar to \renewcommand{\cftdotsep}{1.5}
in tocloft
.
5) I want there to be a space between listings that come from different chapters, just as is done automatically in a list of figures or list of tables.
I think I may be able to create a new list of code using tocloft
, but I really like how listings
color codes my scripts.
Thank you in advance!
Best Answer
I've combed various forums and come up with a solution that works to address all five questions. Please see the code below for comments and explanations.
The List of Code (Page 1):
Some sample code with demonstration of
\autoref
(Page 2)Last page for completeness (Page 3)