Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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