Continuous line numbering in lstlisting, but separate lsttableoflistings entries?
up vote
1
down vote
favorite
i'd like to use the name=something,firstlinenumber=auto
function for continuous line numbering throughout a couple of subsequent listings in my document. I'd also like to have each of the listings have its own separate entry in the List of Listings. The listings
package seems to not like that, though: If I use the same name=something
for multiple listings, only the first one gets an entry in the List of Listings, every other one does not. If I do not use name=something
, each listing gets it's own entry in the List of Listings, but the continuous line numbering no longer works. Minimal example:
documentclass{article}
usepackage{listings}
lstset{numbers=left,firstnumber=auto}
begin{document}
lstlistoflistings
section{Contents}
begin{lstlisting}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{lstlisting}
Listing~ref{first} shows up correctly in the List of Listings.
begin{lstlisting}[name=test,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{lstlisting}
Listing~ref{second} continues the line numbering, and has its own listing number
that can be referenced, but does not receive an entry in the list of Listings.
% parameter "name=test" is removed here..
begin{lstlisting}[label=third,caption=Third Listing]
this restarts the line numbers from line 1
but does get a second entry in the List of Listings
end{lstlisting}
Listing~ref{third} also has its own listing number that can be referenced, and
does get an entry in the List of Listings, but does not continue line numbers.
end{document}
Obviously I could manually count each listings' lines and then manually set the starting line number for each subsequent listing, but I'd prefer a more robust automatic solution. Does anyone know a way to get both behaviors, continuous line numbers AND separate List of Listings entries?
Thanks in advance!
listings line-numbering lstlisting
New contributor
add a comment |
up vote
1
down vote
favorite
i'd like to use the name=something,firstlinenumber=auto
function for continuous line numbering throughout a couple of subsequent listings in my document. I'd also like to have each of the listings have its own separate entry in the List of Listings. The listings
package seems to not like that, though: If I use the same name=something
for multiple listings, only the first one gets an entry in the List of Listings, every other one does not. If I do not use name=something
, each listing gets it's own entry in the List of Listings, but the continuous line numbering no longer works. Minimal example:
documentclass{article}
usepackage{listings}
lstset{numbers=left,firstnumber=auto}
begin{document}
lstlistoflistings
section{Contents}
begin{lstlisting}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{lstlisting}
Listing~ref{first} shows up correctly in the List of Listings.
begin{lstlisting}[name=test,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{lstlisting}
Listing~ref{second} continues the line numbering, and has its own listing number
that can be referenced, but does not receive an entry in the list of Listings.
% parameter "name=test" is removed here..
begin{lstlisting}[label=third,caption=Third Listing]
this restarts the line numbers from line 1
but does get a second entry in the List of Listings
end{lstlisting}
Listing~ref{third} also has its own listing number that can be referenced, and
does get an entry in the List of Listings, but does not continue line numbers.
end{document}
Obviously I could manually count each listings' lines and then manually set the starting line number for each subsequent listing, but I'd prefer a more robust automatic solution. Does anyone know a way to get both behaviors, continuous line numbers AND separate List of Listings entries?
Thanks in advance!
listings line-numbering lstlisting
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i'd like to use the name=something,firstlinenumber=auto
function for continuous line numbering throughout a couple of subsequent listings in my document. I'd also like to have each of the listings have its own separate entry in the List of Listings. The listings
package seems to not like that, though: If I use the same name=something
for multiple listings, only the first one gets an entry in the List of Listings, every other one does not. If I do not use name=something
, each listing gets it's own entry in the List of Listings, but the continuous line numbering no longer works. Minimal example:
documentclass{article}
usepackage{listings}
lstset{numbers=left,firstnumber=auto}
begin{document}
lstlistoflistings
section{Contents}
begin{lstlisting}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{lstlisting}
Listing~ref{first} shows up correctly in the List of Listings.
begin{lstlisting}[name=test,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{lstlisting}
Listing~ref{second} continues the line numbering, and has its own listing number
that can be referenced, but does not receive an entry in the list of Listings.
% parameter "name=test" is removed here..
begin{lstlisting}[label=third,caption=Third Listing]
this restarts the line numbers from line 1
but does get a second entry in the List of Listings
end{lstlisting}
Listing~ref{third} also has its own listing number that can be referenced, and
does get an entry in the List of Listings, but does not continue line numbers.
end{document}
Obviously I could manually count each listings' lines and then manually set the starting line number for each subsequent listing, but I'd prefer a more robust automatic solution. Does anyone know a way to get both behaviors, continuous line numbers AND separate List of Listings entries?
Thanks in advance!
listings line-numbering lstlisting
New contributor
i'd like to use the name=something,firstlinenumber=auto
function for continuous line numbering throughout a couple of subsequent listings in my document. I'd also like to have each of the listings have its own separate entry in the List of Listings. The listings
package seems to not like that, though: If I use the same name=something
for multiple listings, only the first one gets an entry in the List of Listings, every other one does not. If I do not use name=something
, each listing gets it's own entry in the List of Listings, but the continuous line numbering no longer works. Minimal example:
documentclass{article}
usepackage{listings}
lstset{numbers=left,firstnumber=auto}
begin{document}
lstlistoflistings
section{Contents}
begin{lstlisting}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{lstlisting}
Listing~ref{first} shows up correctly in the List of Listings.
begin{lstlisting}[name=test,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{lstlisting}
Listing~ref{second} continues the line numbering, and has its own listing number
that can be referenced, but does not receive an entry in the list of Listings.
% parameter "name=test" is removed here..
begin{lstlisting}[label=third,caption=Third Listing]
this restarts the line numbers from line 1
but does get a second entry in the List of Listings
end{lstlisting}
Listing~ref{third} also has its own listing number that can be referenced, and
does get an entry in the List of Listings, but does not continue line numbers.
end{document}
Obviously I could manually count each listings' lines and then manually set the starting line number for each subsequent listing, but I'd prefer a more robust automatic solution. Does anyone know a way to get both behaviors, continuous line numbers AND separate List of Listings entries?
Thanks in advance!
listings line-numbering lstlisting
listings line-numbering lstlisting
New contributor
New contributor
edited Nov 27 at 8:11
Stefan Pinnow
19.2k83175
19.2k83175
New contributor
asked Nov 27 at 8:05
MisterD
82
82
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
With this marcro
from Yiannis Lazarides's
cheeky answer, you can get the so-called robustness. That is with different naming, you not only continue the line numbering but also get the listings
listed as they appear.
documentclass{article}
%https://tex.stackexchange.com/questions/95036/continue-line-numbers-in-listings-package
usepackage{listings}
lstnewenvironment{bash}[1]
{lstset{language=C}lstset{%
numbers=left,
#1
}}
{}
%
%%% Always I forget this so I created some aliases
defContinueLineNumber{lstset{firstnumber=last}}
defStartLineAt#1{lstset{firstnumber=#1}}
letnumberLineAtStartLineAt
begin{document}
lstlistoflistings
ContinueLineNumber
section{Contents}
begin{bash}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{bash}
Listing~ref{first} shows up correctly in the List of Listings.
begin{bash}[name=test5,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{bash}
No more problems :)
% parameter "name=test" is removed here..
begin{bash}[name=test77, label=third,caption=Third Listing]
this no more restarts the line numbers from line 1
but does continue in the List of Listings
end{bash}
The macro does the job.
end{document}
which will give you:
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
With this marcro
from Yiannis Lazarides's
cheeky answer, you can get the so-called robustness. That is with different naming, you not only continue the line numbering but also get the listings
listed as they appear.
documentclass{article}
%https://tex.stackexchange.com/questions/95036/continue-line-numbers-in-listings-package
usepackage{listings}
lstnewenvironment{bash}[1]
{lstset{language=C}lstset{%
numbers=left,
#1
}}
{}
%
%%% Always I forget this so I created some aliases
defContinueLineNumber{lstset{firstnumber=last}}
defStartLineAt#1{lstset{firstnumber=#1}}
letnumberLineAtStartLineAt
begin{document}
lstlistoflistings
ContinueLineNumber
section{Contents}
begin{bash}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{bash}
Listing~ref{first} shows up correctly in the List of Listings.
begin{bash}[name=test5,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{bash}
No more problems :)
% parameter "name=test" is removed here..
begin{bash}[name=test77, label=third,caption=Third Listing]
this no more restarts the line numbers from line 1
but does continue in the List of Listings
end{bash}
The macro does the job.
end{document}
which will give you:
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
add a comment |
up vote
0
down vote
accepted
With this marcro
from Yiannis Lazarides's
cheeky answer, you can get the so-called robustness. That is with different naming, you not only continue the line numbering but also get the listings
listed as they appear.
documentclass{article}
%https://tex.stackexchange.com/questions/95036/continue-line-numbers-in-listings-package
usepackage{listings}
lstnewenvironment{bash}[1]
{lstset{language=C}lstset{%
numbers=left,
#1
}}
{}
%
%%% Always I forget this so I created some aliases
defContinueLineNumber{lstset{firstnumber=last}}
defStartLineAt#1{lstset{firstnumber=#1}}
letnumberLineAtStartLineAt
begin{document}
lstlistoflistings
ContinueLineNumber
section{Contents}
begin{bash}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{bash}
Listing~ref{first} shows up correctly in the List of Listings.
begin{bash}[name=test5,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{bash}
No more problems :)
% parameter "name=test" is removed here..
begin{bash}[name=test77, label=third,caption=Third Listing]
this no more restarts the line numbers from line 1
but does continue in the List of Listings
end{bash}
The macro does the job.
end{document}
which will give you:
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
With this marcro
from Yiannis Lazarides's
cheeky answer, you can get the so-called robustness. That is with different naming, you not only continue the line numbering but also get the listings
listed as they appear.
documentclass{article}
%https://tex.stackexchange.com/questions/95036/continue-line-numbers-in-listings-package
usepackage{listings}
lstnewenvironment{bash}[1]
{lstset{language=C}lstset{%
numbers=left,
#1
}}
{}
%
%%% Always I forget this so I created some aliases
defContinueLineNumber{lstset{firstnumber=last}}
defStartLineAt#1{lstset{firstnumber=#1}}
letnumberLineAtStartLineAt
begin{document}
lstlistoflistings
ContinueLineNumber
section{Contents}
begin{bash}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{bash}
Listing~ref{first} shows up correctly in the List of Listings.
begin{bash}[name=test5,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{bash}
No more problems :)
% parameter "name=test" is removed here..
begin{bash}[name=test77, label=third,caption=Third Listing]
this no more restarts the line numbers from line 1
but does continue in the List of Listings
end{bash}
The macro does the job.
end{document}
which will give you:
With this marcro
from Yiannis Lazarides's
cheeky answer, you can get the so-called robustness. That is with different naming, you not only continue the line numbering but also get the listings
listed as they appear.
documentclass{article}
%https://tex.stackexchange.com/questions/95036/continue-line-numbers-in-listings-package
usepackage{listings}
lstnewenvironment{bash}[1]
{lstset{language=C}lstset{%
numbers=left,
#1
}}
{}
%
%%% Always I forget this so I created some aliases
defContinueLineNumber{lstset{firstnumber=last}}
defStartLineAt#1{lstset{firstnumber=#1}}
letnumberLineAtStartLineAt
begin{document}
lstlistoflistings
ContinueLineNumber
section{Contents}
begin{bash}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
end{bash}
Listing~ref{first} shows up correctly in the List of Listings.
begin{bash}[name=test5,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
end{bash}
No more problems :)
% parameter "name=test" is removed here..
begin{bash}[name=test77, label=third,caption=Third Listing]
this no more restarts the line numbers from line 1
but does continue in the List of Listings
end{bash}
The macro does the job.
end{document}
which will give you:
answered Nov 27 at 8:33
Raaja
2,0742525
2,0742525
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
add a comment |
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
1
1
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
Ohh I see. I had seen this macro and tried using it, but it didn't work because I used it wrong. Now I see how it's supposed to be used, and it indeed does the job. Thanks!
– MisterD
Nov 27 at 8:44
add a comment |
MisterD is a new contributor. Be nice, and check out our Code of Conduct.
MisterD is a new contributor. Be nice, and check out our Code of Conduct.
MisterD is a new contributor. Be nice, and check out our Code of Conduct.
MisterD is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461960%2fcontinuous-line-numbering-in-lstlisting-but-separate-lsttableoflistings-entries%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown