2

I use algorithm2e to put algorithms in my documents, and I use \listofalgorithms to have a list of my algorithms in the table of contents but I noticed that their title size are a bit different: "List of algorithms" is a bit smaller. Is there a way to fixe this ?

My second problem is the labelformat that I use with varioref to insert alg. in front of the number of the algorithms that I cite (with vref command). It works with equation, figure, table, section... environments, but not with the algorithm environment. I don't understant why.

Here is my code:

\documentclass[onecolumn,twoside,openright,a4paper,11pt]{report}
\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        
\usepackage{hyperref}       %

\usepackage[lined,dotocloa,algochapter]{algorithm2e}    % 

\usepackage{varioref}
\makeatletter       % 
    \labelformat{algorithm}{\textit{alg.}\,(#1)}
\makeatother

\begin{document}

\tableofcontents        % 
\thispagestyle{empty}

\listofalgorithms       % 
\thispagestyle{empty}


\chapter{section1}

\IncMargin{1em}
\begin{algorithm}
\SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\BlankLine
\emph{special treatment of the first line}\;
\For{$i\leftarrow 2$ \KwTo $l$}{
\emph{special treatment of the first element of line $i$}\;
\For{$j\leftarrow 2$ \KwTo $w$}{\label{forins}
\Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}\;
\Up$\leftarrow$ \FindCompress{$Im[i-1,]$}\;
\This$\leftarrow$ \FindCompress{$Im[i,j]$}\;
\If(\tcp*[h]{O(\Left,\This)==1}){\Left compatible with \This}{\label{lt}
\lIf{\Left $<$ \This}{\Union{\Left,\This}}\;
\lElse{\Union{\This,\Left}\;}
}
\If(\tcp*[f]{O(\Up,\This)==1}){\Up compatible with \This}{\label{ut}
\lIf{\Up $<$ \This}{\Union{\Up,\This}}\;
\tcp{\This is put under \Up to keep tree as flat as possible}\label{cmt}
\lElse{\Union{\This,\Up}}\tcp*[r]{\This linked to \Up}\label{lelse}
}
}
\lForEach{element $e$ of the line $i$}{\FindCompress{p}}
}
\caption{disjoint decomposition}\label{algo_disjdecomp}
\end{algorithm}\DecMargin{1em}.

\vref{algo_disjdecomp}

\end{document}

Does anyone can help me ?

1 Answer 1

2

I don't see any difference in the List of Algorithms size and that of Contents - they're both set as a \chapter* and therefore should look the same.

In terms of the label reference, you're setting the \labelformat for a non-existent counter. In fact, algorithm2e uses the counter algocf rather than algorithm.

enter image description here

\documentclass{report}
\usepackage{varioref}
\usepackage{hyperref}

\usepackage[lined,dotocloa,algochapter]{algorithm2e}
\SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}

\labelformat{algocf}{\textit{alg.}\,(#1)}

\begin{document}

\tableofcontents

\listofalgorithms

\chapter{First chapter}

\begin{algorithm}
  \Input{A bitmap $I$ of size $w \times l$}
  \Output{A partition of the bitmap}
  \BlankLine
  \emph{special treatment of the first line}\;
  \For{$i \leftarrow 2$ \KwTo $l$}{
    \emph{special treatment of the first element of line $i$}\;
    \For{$j \leftarrow 2$ \KwTo $w$}{\label{forins}
      $\Left \leftarrow \FindCompress{$I[i,j-1]$}$\;
      $\Up \leftarrow \FindCompress{$I[i-1,]$}$\;
      $\This \leftarrow \FindCompress{$I[i,j]$}$\;
      \If(\tcp*[h]{O(\Left,\This)==1}){\Left compatible with \This}{\label{lt}
        \lIf{$\Left < \This$}{$\Union{\Left,\This}$}
        \lElse{$\Union{\This,\Left}$}
      }
      \If(\tcp*[f]{O(\Up,\This)==1}){\Up compatible with \This}{\label{ut}
        \lIf{$\Up < \This$}{$\Union{\Up,\This}$}
        \tcp{\This is put under \Up to keep tree as flat as possible}\label{cmt}
        \lElse{$\Union{\This,\Up}$}\tcp*[r]{\This{} linked to \Up}\label{lelse}
      }
    }
    \lForEach{element $e$ of the line $i$}{\FindCompress{p}}
  }
  \caption{disjoint decomposition}\label{algo_disjdecomp}
\end{algorithm}

\vref{algo_disjdecomp}

\end{document}

Since you are using hyperref, load it after varioref.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .