1

I'm having some issues with modifying the vertical skip between each entry in my List of Listings. Everything else in the list works perfectly, but I need to increase the vertical skip to 2pt (similar to what’s done for tables and figures, as shown below):

\setlength{\cftbeforefigskip}{2pt} 

Here's all the code I'm currently using to define the List of Listings:

\renewcommand\lstlistlistingname{List of Listings} \addtocontents{lol}{\protect\addvspace{-1.5cm}} \makeatletter \renewcommand{\l@lstlisting}{\@dottedtocline{1}{0.25in}{0.5in}} % lstlisting format \renewcommand{\l@listing}{\@dottedtocline{1}{0.25in}{0.5in} \vspace{1\baselineskip}} % listing format \makeatother \addtocontents{lol}{\protect\vspace{15pt}} % Defined on each chapter to create space between entries %% List of Listings %% \titlespacing*{\chapter}{0pt}{-0.5cm}{*4} % Adjusts section spacing \phantomsection \label{Listings} \lstlistoflistings \addcontentsline{toc}{chapter}{List of Listings} \addtocontents{toc}{\vspace{2ex}~\hfill\textbf{Page}\par} \label{LastMainPage-roman} 

Here is an example:

\documentclass{article} \usepackage{graphicx} % Required for inserting images \usepackage{listings} \usepackage{titlesec} \usepackage{minted} \usepackage{tocloft} % For customizing table of contents \usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref} \usepackage{newfloat} \usepackage{caption} \begin{document} \setcounter{secnumdepth}{2} % 3 for subsubsections \setcounter{tocdepth}{2} \tableofcontents \newpage \renewcommand\lstlistlistingname{List of Listings} % Define the dotline for the List of Listings \makeatletter \renewcommand{\l@listing}{\@dottedtocline{1}{0.25in}{0.5in}} % Customize dotline format \makeatother %% List of Listings %% \phantomsection \addcontentsline{toc}{section}{List of Listings} \lstlistoflistings \newpage \begin{listing}[!ht] \begin{minted}[bgcolor=white, linenos, framesep=2mm, breaklines, fontsize=\small]{python} import sympy as sm import sympy.physics.mechanics as me # this is to get nice looking output sm.init_printing() # h: cross-section depth [m] # b: cross-section width [m] # g: gravity [m/s^2] # l: length of pendulum [m] # rho: density of pendulum [kg/m^3] # constant parameters that define our problem (simple pendulum) h, b, g, l, rho, tau1, tau2 = sm.symbols('h, b, g, l, rho, tau_1, tau_2') m = b * h * l * rho # mass of the pendulum Izz = m * l**2 / 12 # moment of inertia of the pendulum around the z-axis (both N and A) # generalized coordinates (time dependent) q1, q2 = me.dynamicsymbols('q1, q2') # time variable (used for derivatives) t = me.dynamicsymbols._t \end{minted} \caption{Test 1} \label{listing:1} \end{listing} \begin{listing}[!ht] \begin{minted}[bgcolor=white, linenos, framesep=2mm, breaklines, fontsize=\small]{python} import sympy as sm import sympy.physics.mechanics as me # this is to get nice looking output sm.init_printing() # h: cross-section depth [m] # b: cross-section width [m] # g: gravity [m/s^2] # l: length of pendulum [m] # rho: density of pendulum [kg/m^3] # constant parameters that define our problem (simple pendulum) h, b, g, l, rho, tau1, tau2 = sm.symbols('h, b, g, l, rho, tau_1, tau_2') m = b * h * l * rho # mass of the pendulum Izz = m * l**2 / 12 # moment of inertia of the pendulum around the z-axis (both N and A) # generalized coordinates (time dependent) q1, q2 = me.dynamicsymbols('q1, q2') # time variable (used for derivatives) t = me.dynamicsymbols._t \end{minted} \caption{Test 2} \label{listing:2} \end{listing} \end{document} 
0

1 Answer 1

0

You should use listing and not listings. I also copied the infrastructure of tocloft for “figure”, so you can use the standard tocloft methods also for the list of listings, in particular the “before skip” that I set to 6pt (adapt to your liking).

Don't forget the titles option to tocloft.

\documentclass{article} \usepackage{graphicx} % Required for inserting images \usepackage{titlesec} \usepackage{listing} \usepackage{minted} \usepackage[titles]{tocloft} % For customizing table of contents \usepackage{newfloat} \usepackage{caption} \usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref} % Define the dotline for the List of Listings \makeatletter \renewcommand*{\l@listing}[2]{% % \ifnum \c@lofdepth >\z@ \vskip \cftbeforelstskip {\leftskip \cftlstindent\relax \rightskip \@tocrmarg \parfillskip -\rightskip \parindent \cftlstindent\relax\@afterindenttrue \interlinepenalty\@M \leavevmode \@tempdima \cftlstnumwidth\relax \let\@cftbsnum \cftlstpresnum \let\@cftasnum \cftlstaftersnum \let\@cftasnumb \cftlstaftersnumb \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip {\cftlstfont #1}\nobreak \cftlstfillnum{#2}}% % \fi } \newlength{\cftbeforelstskip} \setlength{\cftbeforelstskip}{6pt plus 0.2pt} % <--- adapt to your liking \newlength{\cftlstindent} \setlength{\cftlstindent}{1.5em} \newlength{\cftlstnumwidth} \setlength{\cftlstnumwidth}{2.3em} \newcommand{\cftlstfont}{\normalfont} \newcommand{\cftlstpresnum}{} \newcommand{\cftlstaftersnum}{} \newcommand{\cftlstaftersnumb}{} \newcommand{\cftlstleader}{\normalfont\cftdotfill{\cftlstdotsep}} \newcommand{\cftlstdotsep}{\cftdotsep} \newcommand{\cftlstpagefont}{\normalfont} \newcommand{\cftlstafterpnum}{} \newcommand{\cftlstfillnum}[1]{% {\cftlstleader}\nobreak \makebox[\@pnumwidth][\cftpnumalign]{\cftlstpagefont #1}\cftlstafterpnum\par }\makeatother \begin{document} \setcounter{secnumdepth}{2} % 3 for subsubsections \setcounter{tocdepth}{2} \tableofcontents \clearpage %% List of Listings %% \phantomsection \addcontentsline{toc}{section}{List of Listings} \listoflistings \clearpage \begin{listing}[!ht] \begin{minted}[bgcolor=white, linenos, framesep=2mm, breaklines, fontsize=\small]{python} import sympy as sm import sympy.physics.mechanics as me # this is to get nice looking output sm.init_printing() # h: cross-section depth [m] # b: cross-section width [m] # g: gravity [m/s^2] # l: length of pendulum [m] # rho: density of pendulum [kg/m^3] # constant parameters that define our problem (simple pendulum) h, b, g, l, rho, tau1, tau2 = sm.symbols('h, b, g, l, rho, tau_1, tau_2') m = b * h * l * rho # mass of the pendulum Izz = m * l**2 / 12 # moment of inertia of the pendulum around the z-axis (both N and A) # generalized coordinates (time dependent) q1, q2 = me.dynamicsymbols('q1, q2') # time variable (used for derivatives) t = me.dynamicsymbols._t \end{minted} \caption{Test 1} \label{listing:1} \end{listing} \begin{listing}[!ht] \begin{minted}[bgcolor=white, linenos, framesep=2mm, breaklines, fontsize=\small]{python} import sympy as sm import sympy.physics.mechanics as me # this is to get nice looking output sm.init_printing() # h: cross-section depth [m] # b: cross-section width [m] # g: gravity [m/s^2] # l: length of pendulum [m] # rho: density of pendulum [kg/m^3] # constant parameters that define our problem (simple pendulum) h, b, g, l, rho, tau1, tau2 = sm.symbols('h, b, g, l, rho, tau_1, tau_2') m = b * h * l * rho # mass of the pendulum Izz = m * l**2 / 12 # moment of inertia of the pendulum around the z-axis (both N and A) # generalized coordinates (time dependent) q1, q2 = me.dynamicsymbols('q1, q2') # time variable (used for derivatives) t = me.dynamicsymbols._t \end{minted} \caption{Test 2} \label{listing:2} \end{listing} \end{document} 

output

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.