3

I'm writing my bachelor thesis in my university's template fithesis3.

It automatically sets the style of the List of Images as such: List of Images

, with a Roman page number.

I'm trying to create a similar listing, List of Source code examples to be more precise. I'm using minted for source code highlighting and wrapping it in listing to be able to set a caption and a reference for it.

So far I've been able to change the default caption name and the default name of the listing as well, but I have yet to successfully change the listing's style.

The code I'm using is: I've edited the source code example to be the smallest compilable version I could, as was adviced in the comments.

\documentclass[digital, table, lof, nolot]{fithesis3}
%%<http://mirrors.ctan.org/macros/latex/contrib/fithesis/guide/mu/fi.pdf>
\usepackage[resetfonts]{cmap} %% We need to load the T2A font encoding
\usepackage[T1,T2A]{fontenc}  %% to use the Cyrillic fonts with Russian texts.
\usepackage[main=english, slovak, german, russian, czech]{babel}
\usepackage{paratype}
\def\textrussian#1{{\usefont{T2A}{PTSerif-TLF}{m}{rm}#1}}
\usepackage[utf8]{inputenc}
\thesissetup{
    date          = \the\year/\the\month/\the\day,
    university    = mu,
    faculty       = fi,
    type          = bc,
    author        = Name Surname,
    gender        = m,
    advisor       = Professor's name,
    title         = {Thesis Name},
    TeXtitle      = {Thesis Name},
    keywords      = {keywords},
    TeXkeywords   = {keywords},
}
\thesislong{abstract}{Abstract goes here.}
\thesislong{thanks}{Thanks goes here.}
\usepackage{makeidx}
\makeindex
\usepackage{paralist}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{url}
\usepackage{markdown}
\usepackage{float}
%%source code highlighting
\usepackage[chapter]{minted}
\usepackage{color}
\definecolor{codebg}{rgb}{0.95,0.95,0.95}
\setminted{tabsize=3, linenos=true, xleftmargin=21pt, bgcolor=codebg, samepage=false, breaklines=true, breakafter=., breakaftersymbolpre=}
\renewcommand{\listingscaption}{Code}
\renewcommand{\listoflistingscaption}{List of source code examples}
\begin{document}
%%list of listings hack
\pagenumbering{roman}
\setcounter{page}{11}
\listoflistings
\newpage\null\thispagestyle{empty}\newpage
\pagenumbering{arabic}
\setcounter{page}{1}
\chapter{Test chapter}
\section{Test section}
Test page with a test figure and a test source code example.
\begin{figure}[H]
  \begin{center}
    \includegraphics[width=2.15cm]{fithesis/logo/mu/fithesis-base.pdf}
  \end{center}
  \caption{The logo of the Masaryk University}
  \label{fig:mulogo1}
\end{figure}
\begin{listing}[H]
\begin{minted}{js}
// create data
var circles = [
    { x: 12,  y: 39, radius: 7, color: "green" },
    { x: 25,  y: 20, radius: 11, color: "blue" }];

// create SVG container
var svg = d3.select("body").append("svg")
    .attr("width", 50).attr("height", 50);

// create SVG elements from data
svg.selectAll("circle") // circle template
    .data(circles)       // link data
    .enter()                 // for each data
    .append("circle")    // add a circle 
    // and set it's parameters
    .attr("cx", function(d) { return d.x })
    .attr("cy", function(d) { return d.y })
    .attr("r", function(d) { return d.radius })
    .attr("fill", function(d) { return d.color });
\end{minted}
\caption{Creating SVG elements from data}
\label{src:elefromdata}
\end{listing}
\end{document}

but the formatting of the List of Listings it generates looks like this: List of Listings

I've been tampering with the answer from the post linked below, but I've only been able to change the looks of both List of Figures and List of Listings to look very similar to my original List of Listings, only change being that the list items aren't indented anymore. My code looks like this:

\usepackage[titles]{tocloft}
\newlistof{listing}{lol}{Zoznam ukážok zdrojového kódu}
\usepackage[newfloat]{minted}
\usepackage{caption}

\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{%
  name={Kód},
  fileext=lol}

\setlength{\cftfigindent}{0pt}
\setlength{\cftlistingnumwidth}{1cm}
\setlength{\cftfignumwidth}{1cm}

\setminted{tabsize=3, linenos=true, xleftmargin=21pt, bgcolor=codebg, samepage=false, breaklines=true, breakafter=., breakaftersymbolpre=}

Is there any way to change it's style to look like the original List of Images' one? The changes I need to be made:

  • disable the offset of each list item
  • remove the dotted lines
  • put the page number in a set size (one tab?) after the list item's name
  • emphasize the page number

I've tried searching this forum a lot, but haven't been able to find anything (maybe I don't know the proper terminology?).

I stumbled upon this Customizing the list of listings from minted thread, which seems to solve a problem very similar to mine, but I wasn't able to fix my problem even with it's help.

Thanks for any and all help.

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Also, please specify what your problems are in implementing the solution from the link you've provided. – jjdb May 17 '17 at 16:36
  • @jjdb I've done both, thanks for your advice! – tinnyx May 17 '17 at 22:39
1

You can copy the stuff for the list of figures to be used for the listings as well

\let\l@listing\l@figure
\let\listoflistings\listoffigures

and then patch \listoflistings with the necessary changes

% use the right auxiliary file:
\patchcmd{\listoflistings}{lof}{lol}{}{}
% exchange \listfigurename three times with \listoflistingscaption
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}

Note that \patchcmd needs the etoolbox package loaded and \l@figure/\l@listing need @ to be a letter:

\usepackage{etoolbox}
\makeatletter
\let\l@listing\l@figure
\let\listoflistings\listoffigures
\patchcmd{\listoflistings}{lof}{lol}{}{}
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}
\patchcmd{\listoflistings}{\listfigurename}{\listoflistingscaption}{}{}
\makeatother

I then get

enter image description here

and

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.