# How to combine the listings and algorithm2e packages to be used with List of Listings

I want to make a "List of Algorithms and Listings" that contains both listings made with \begin{lstlisting}... (listings package) and algorithms \begin{algorithm}... (algorithm2e package).

I also want the numbering to be continuous in the List of..., no matter how I alternate between listings and algorithms.

I have tried to use the listings package to make the List of... and to put something like \addcontentsline{lol}{section}{\numberline {\thelstlisting}This is a test} after \end{algorithm}, but that entry does not get properly numbered.

10x.

-

It would have been nice if you added a MWE, so we could immediately test our ideas.

Anyway, I think, using your approach with \addcontentsline it is sufficient to add a \refstepcounter{lstlisting} in front. Also I would suggest putting those two lines in front of the \begin{algorithm} instead of after \end{algorithm} as the anchor is more convenient there.

If that is not sufficient for you, you could define your own list of listings with the tocloft package and define some wrapper environments for lstlisting and algorithm. An example where you can see this is this previous answer of mine.

-
Thank you for you answer. It partially solved the numbering problem. The thing is I have an algorithm that takes up the whole page and then a listing. So the numbering would be: 1. Algorithm on page 1; 2. Listing on page 2. The problem is that, if I put the \refstepcounter... in from of \begin{algorithm} then I will get 1. Algorithm on page 2; 2. Listing on page 1. If I put the code after \begin{algorithm}, then I will get 2. Algorithm on page 1; 1. Listing on page 2. (in this order)... any ideas? ... besides using tocloft? –  adrian Aug 24 '12 at 15:08
@adrian: Try to add a \phantomsection before \addcontentsline. –  canaaerus Aug 24 '12 at 16:13
Thanks for the suggestion. Unfortunately it din dot work for me, but I found a workaroud by beeing careful about where I put the algorithm that takes the whole page. –  adrian Aug 25 '12 at 6:23