Going against what I thought it was, the problem was the hyperref package. As this other post here hinted, the include's order was bogus, but also I had to add a \phantomsection
.
So, my preamble was
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% color
\usepackage[table,dvipsnames]{xcolor}
% Blue links
\usepackage[unicode,colorlinks=true,linkcolor=blue]{hyperref}
% "Natbib" style for references
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp]{biblatex}
% \makeglossaries
% http://en.wikibooks.org/wiki/LaTeX/Glossary#Using_defined_terms
\usepackage[xindy,toc]{glossaries}
% http://texblog.org/tag/addcontentsline/
\usepackage[numbib]{tocbibind}
% \newminted{cpp}
% [chapter] to number by chapter
\usepackage[chapter]{minted}
% TODO anotations
\usepackage[colorinlistoftodos,portuguese]{todonotes}
\usepackage{float}
\usepackage{caption} % \begin{caption}
\usepackage{csquotes} % required by {babel}
\usepackage{graphicx} % \includegraphics
\usepackage{subcaption} % \begin{subfigure}
\usepackage{verbatim} % \begin{comment}
\usepackage{fullpage} % thinner margins
\usepackage{indentfirst} % indent 1st paragraphs
\usepackage{setspace} % \setstretch
\usepackage{afterpage} % \afterpage https://tex.stackexchange.com/q/88657
% turning 'fi' ligatures off
% http://www.latex-community.org/forum/viewtopic.php?f=5&t=953#p13896
\usepackage{microtype}
\DisableLigatures{encoding = *, family = *}
Changing the include's order, turned into
\usepackage[brazil]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% color
\usepackage[table,dvipsnames]{xcolor}
\usepackage{caption} % \begin{caption}
\usepackage{csquotes} % required by {babel}
\usepackage{graphicx} % \includegraphics
\usepackage{subcaption} % \begin{subfigure}
\usepackage{verbatim} % \begin{comment}
\usepackage{fullpage} % thinner margins
\usepackage{indentfirst} % indent 1st paragraphs
\usepackage{setspace} % \setstretch
\usepackage{afterpage} % \afterpage https://tex.stackexchange.com/q/88657
% \newminted{cpp}
% [chapter] to number by chapter
\usepackage[chapter]{minted}
% Blue links
\usepackage[unicode,colorlinks=true,linkcolor=blue]{hyperref}
% turning 'fi' ligatures off
% http://www.latex-community.org/forum/viewtopic.php?f=5&t=953#p13896
\usepackage{microtype}
\DisableLigatures{encoding = *, family = *}
% "Natbib" style for references
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp]{biblatex}
% \makeglossaries
% http://en.wikibooks.org/wiki/LaTeX/Glossary#Using_defined_terms
\usepackage[xindy,toc]{glossaries}
% http://texblog.org/tag/addcontentsline/
\usepackage[numbib]{tocbibind}
% TODO anotations
\usepackage[colorinlistoftodos,portuguese]{todonotes}
and the renew command for \listoflistings
with the \phantomsection
% https://tex.stackexchange.com/a/99656/5125
\renewcommand{\listoflistings}{%
\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\listoflistingscaption}%
\listof{listing}{\listoflistingscaption}%
}
Now, clicking the list of listings entry on table of contents guides to the right page of the listing.
To put a box, you don't need to wrap minted
inside listing
. A simple frame=single
will do it. But listing
wrapper is helpful in putting a caption (putting a \label
) and producing a list of listings
.
\documentclass[a4paper , 12pt]{article}
\usepackage{minted}
\usemintedstyle{emacs}
\renewcommand\listingscaption{Program}
\renewcommand\listoflistingscaption{List of Java codes}
\begin{document}
\listoflistings
\begin{listing}
\begin{minted}[bgcolor=olive!10]{java} %% or frame=single
class Test
{
public static void main(String args[])
{
System.out.println("Hello World");
}
}
\end{minted}
\caption{My Java Code}\label{java:sample}
\end{listing}
\end{document}
If you want a frame add frame=single
as in
\begin{minted}[bgcolor=olive!10,frame=single]{java}
Best Answer
You should load
minted
beforeclassicthesis
, otherwise you get awarning, with incorrect hyperlinks.
Then you can make
\l@listing
the same as\l@figure
, which is whatnewfloat
does anyway, but afterclassicthesis
has modified the standard meaning of\l@figure
. You can use a hook, usually empty, for locally changing\figurename
to “Listing” and, possibly, for changing some of the indentation parameters.With
babel
it seems that some timing problems arise. Here's a different workaround, including the change to the labels.