Strange behaviour using center, tcolorbox, listings and enumerate
up vote
3
down vote
favorite
I have a problem compiling the following minimal example:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I cannot reduce anything and don't know if the problem is dedicated to listings, tcolorbox, enumerate or center. (maybe all of them together)
The error is
! LaTeX Error: Something's wrong--perhaps a missing item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 ^^I^^I^^Iitem o
ne
which is (like most LaTeX errors) not very useful…
errors listings enumerate tcolorbox compilation-error
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
3
down vote
favorite
I have a problem compiling the following minimal example:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I cannot reduce anything and don't know if the problem is dedicated to listings, tcolorbox, enumerate or center. (maybe all of them together)
The error is
! LaTeX Error: Something's wrong--perhaps a missing item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 ^^I^^I^^Iitem o
ne
which is (like most LaTeX errors) not very useful…
errors listings enumerate tcolorbox compilation-error
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to TeX.SE. If you removebegin{center}andend{center}and instead use{centering.... }%the problem is resolved. Plus using thecenterenvironment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.
– Peter Grill
Nov 20 at 18:11
What's thecenterenvironment supposed to do? Thelstlistingenvironment will use the whole text width anyway.
– egreg
Nov 20 at 18:33
Why using thebegin{center} ... end{center}environment or thecenteringcommand while we could simply use thetcolorboxenvironment with thecenteroption?begin{tcolorbox}[center] ... end{tcolorbox}
– Hafid Boukhoulda
Nov 21 at 19:50
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a problem compiling the following minimal example:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I cannot reduce anything and don't know if the problem is dedicated to listings, tcolorbox, enumerate or center. (maybe all of them together)
The error is
! LaTeX Error: Something's wrong--perhaps a missing item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 ^^I^^I^^Iitem o
ne
which is (like most LaTeX errors) not very useful…
errors listings enumerate tcolorbox compilation-error
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a problem compiling the following minimal example:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I cannot reduce anything and don't know if the problem is dedicated to listings, tcolorbox, enumerate or center. (maybe all of them together)
The error is
! LaTeX Error: Something's wrong--perhaps a missing item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 ^^I^^I^^Iitem o
ne
which is (like most LaTeX errors) not very useful…
errors listings enumerate tcolorbox compilation-error
errors listings enumerate tcolorbox compilation-error
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 20 at 18:02
Ben
161
161
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Welcome to TeX.SE. If you removebegin{center}andend{center}and instead use{centering.... }%the problem is resolved. Plus using thecenterenvironment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.
– Peter Grill
Nov 20 at 18:11
What's thecenterenvironment supposed to do? Thelstlistingenvironment will use the whole text width anyway.
– egreg
Nov 20 at 18:33
Why using thebegin{center} ... end{center}environment or thecenteringcommand while we could simply use thetcolorboxenvironment with thecenteroption?begin{tcolorbox}[center] ... end{tcolorbox}
– Hafid Boukhoulda
Nov 21 at 19:50
add a comment |
1
Welcome to TeX.SE. If you removebegin{center}andend{center}and instead use{centering.... }%the problem is resolved. Plus using thecenterenvironment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.
– Peter Grill
Nov 20 at 18:11
What's thecenterenvironment supposed to do? Thelstlistingenvironment will use the whole text width anyway.
– egreg
Nov 20 at 18:33
Why using thebegin{center} ... end{center}environment or thecenteringcommand while we could simply use thetcolorboxenvironment with thecenteroption?begin{tcolorbox}[center] ... end{tcolorbox}
– Hafid Boukhoulda
Nov 21 at 19:50
1
1
Welcome to TeX.SE. If you remove
begin{center} and end{center} and instead use {centering.... }% the problem is resolved. Plus using the center environment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.– Peter Grill
Nov 20 at 18:11
Welcome to TeX.SE. If you remove
begin{center} and end{center} and instead use {centering.... }% the problem is resolved. Plus using the center environment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.– Peter Grill
Nov 20 at 18:11
What's the
center environment supposed to do? The lstlisting environment will use the whole text width anyway.– egreg
Nov 20 at 18:33
What's the
center environment supposed to do? The lstlisting environment will use the whole text width anyway.– egreg
Nov 20 at 18:33
Why using the
begin{center} ... end{center} environment or the centering command while we could simply use the tcolorbox environment with the center option? begin{tcolorbox}[center] ... end{tcolorbox}– Hafid Boukhoulda
Nov 21 at 19:50
Why using the
begin{center} ... end{center} environment or the centering command while we could simply use the tcolorbox environment with the center option? begin{tcolorbox}[center] ... end{tcolorbox}– Hafid Boukhoulda
Nov 21 at 19:50
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
The begin{center} confuses tcolorbox besides adding undesirable additional vertical space. Either add leavevmode before begin{tcolorbox} or better use {centering.... } as suggested by @PeterGrill in a comment.
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}leavevmode
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I think you need to include apar:{centering ... par}.
– Peter Grill
Nov 20 at 18:31
add a comment |
up vote
1
down vote
Update: removal of borders.
It seems to me that from your own response to your problem that you don't want the listing to be in a visible box. And as with tcolorbox, everything is configurable, just set it up.
- With the
skin=emptyparameter, nothing is drawn at all: so there is no border (see page 237). - With the parameter
lowerbox=ignorednot to display the lower part of the box (see p 24).
It is therefore also possible to set the distances between the content of the listing and the rest of the box, but i did not do.

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{tcblisting}{skin=empty,lowerbox=ignored}
alert(123);
end{tcblisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Old answer:
It is possible to use the dispListing environment of the tcolorbox documentation library (see page 465 of the 4.14 manual).

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
tcbuselibrary{documentation}
begin{document}
begin{center}
begin{tcolorbox}
begin{dispListing}
alert(123);
end{dispListing}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Translated with www.DeepL.com/Translator
add a comment |
up vote
0
down vote
Thank's to @AboAmmar , @PeterGrill and @egreg who managed to find out the source of the error namely the center environment.
To get the the tcolorbox centered we can use its center option:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
noindenthrulefill % this rule is added to show that the box is actually centered
begin{tcolorbox}[width=0.75linewidth,center]
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
noindenthrulefill
end{document}

add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The begin{center} confuses tcolorbox besides adding undesirable additional vertical space. Either add leavevmode before begin{tcolorbox} or better use {centering.... } as suggested by @PeterGrill in a comment.
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}leavevmode
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I think you need to include apar:{centering ... par}.
– Peter Grill
Nov 20 at 18:31
add a comment |
up vote
2
down vote
The begin{center} confuses tcolorbox besides adding undesirable additional vertical space. Either add leavevmode before begin{tcolorbox} or better use {centering.... } as suggested by @PeterGrill in a comment.
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}leavevmode
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
I think you need to include apar:{centering ... par}.
– Peter Grill
Nov 20 at 18:31
add a comment |
up vote
2
down vote
up vote
2
down vote
The begin{center} confuses tcolorbox besides adding undesirable additional vertical space. Either add leavevmode before begin{tcolorbox} or better use {centering.... } as suggested by @PeterGrill in a comment.
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}leavevmode
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
The begin{center} confuses tcolorbox besides adding undesirable additional vertical space. Either add leavevmode before begin{tcolorbox} or better use {centering.... } as suggested by @PeterGrill in a comment.
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
begin{center}leavevmode
begin{tcolorbox}
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
answered Nov 20 at 18:15
AboAmmar
31.4k22781
31.4k22781
I think you need to include apar:{centering ... par}.
– Peter Grill
Nov 20 at 18:31
add a comment |
I think you need to include apar:{centering ... par}.
– Peter Grill
Nov 20 at 18:31
I think you need to include a
par: {centering ... par}.– Peter Grill
Nov 20 at 18:31
I think you need to include a
par: {centering ... par}.– Peter Grill
Nov 20 at 18:31
add a comment |
up vote
1
down vote
Update: removal of borders.
It seems to me that from your own response to your problem that you don't want the listing to be in a visible box. And as with tcolorbox, everything is configurable, just set it up.
- With the
skin=emptyparameter, nothing is drawn at all: so there is no border (see page 237). - With the parameter
lowerbox=ignorednot to display the lower part of the box (see p 24).
It is therefore also possible to set the distances between the content of the listing and the rest of the box, but i did not do.

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{tcblisting}{skin=empty,lowerbox=ignored}
alert(123);
end{tcblisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Old answer:
It is possible to use the dispListing environment of the tcolorbox documentation library (see page 465 of the 4.14 manual).

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
tcbuselibrary{documentation}
begin{document}
begin{center}
begin{tcolorbox}
begin{dispListing}
alert(123);
end{dispListing}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Translated with www.DeepL.com/Translator
add a comment |
up vote
1
down vote
Update: removal of borders.
It seems to me that from your own response to your problem that you don't want the listing to be in a visible box. And as with tcolorbox, everything is configurable, just set it up.
- With the
skin=emptyparameter, nothing is drawn at all: so there is no border (see page 237). - With the parameter
lowerbox=ignorednot to display the lower part of the box (see p 24).
It is therefore also possible to set the distances between the content of the listing and the rest of the box, but i did not do.

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{tcblisting}{skin=empty,lowerbox=ignored}
alert(123);
end{tcblisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Old answer:
It is possible to use the dispListing environment of the tcolorbox documentation library (see page 465 of the 4.14 manual).

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
tcbuselibrary{documentation}
begin{document}
begin{center}
begin{tcolorbox}
begin{dispListing}
alert(123);
end{dispListing}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Translated with www.DeepL.com/Translator
add a comment |
up vote
1
down vote
up vote
1
down vote
Update: removal of borders.
It seems to me that from your own response to your problem that you don't want the listing to be in a visible box. And as with tcolorbox, everything is configurable, just set it up.
- With the
skin=emptyparameter, nothing is drawn at all: so there is no border (see page 237). - With the parameter
lowerbox=ignorednot to display the lower part of the box (see p 24).
It is therefore also possible to set the distances between the content of the listing and the rest of the box, but i did not do.

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{tcblisting}{skin=empty,lowerbox=ignored}
alert(123);
end{tcblisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Old answer:
It is possible to use the dispListing environment of the tcolorbox documentation library (see page 465 of the 4.14 manual).

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
tcbuselibrary{documentation}
begin{document}
begin{center}
begin{tcolorbox}
begin{dispListing}
alert(123);
end{dispListing}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Translated with www.DeepL.com/Translator
Update: removal of borders.
It seems to me that from your own response to your problem that you don't want the listing to be in a visible box. And as with tcolorbox, everything is configurable, just set it up.
- With the
skin=emptyparameter, nothing is drawn at all: so there is no border (see page 237). - With the parameter
lowerbox=ignorednot to display the lower part of the box (see p 24).
It is therefore also possible to set the distances between the content of the listing and the rest of the box, but i did not do.

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
begin{document}
begin{center}
begin{tcolorbox}
begin{tcblisting}{skin=empty,lowerbox=ignored}
alert(123);
end{tcblisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Old answer:
It is possible to use the dispListing environment of the tcolorbox documentation library (see page 465 of the 4.14 manual).

documentclass{article}
%usepackage{listings}
usepackage[most]{tcolorbox}
tcbuselibrary{documentation}
begin{document}
begin{center}
begin{tcolorbox}
begin{dispListing}
alert(123);
end{dispListing}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
end{center}
end{document}
Translated with www.DeepL.com/Translator
edited Nov 20 at 21:16
answered Nov 20 at 18:21
AndréC
6,24711140
6,24711140
add a comment |
add a comment |
up vote
0
down vote
Thank's to @AboAmmar , @PeterGrill and @egreg who managed to find out the source of the error namely the center environment.
To get the the tcolorbox centered we can use its center option:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
noindenthrulefill % this rule is added to show that the box is actually centered
begin{tcolorbox}[width=0.75linewidth,center]
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
noindenthrulefill
end{document}

add a comment |
up vote
0
down vote
Thank's to @AboAmmar , @PeterGrill and @egreg who managed to find out the source of the error namely the center environment.
To get the the tcolorbox centered we can use its center option:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
noindenthrulefill % this rule is added to show that the box is actually centered
begin{tcolorbox}[width=0.75linewidth,center]
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
noindenthrulefill
end{document}

add a comment |
up vote
0
down vote
up vote
0
down vote
Thank's to @AboAmmar , @PeterGrill and @egreg who managed to find out the source of the error namely the center environment.
To get the the tcolorbox centered we can use its center option:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
noindenthrulefill % this rule is added to show that the box is actually centered
begin{tcolorbox}[width=0.75linewidth,center]
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
noindenthrulefill
end{document}

Thank's to @AboAmmar , @PeterGrill and @egreg who managed to find out the source of the error namely the center environment.
To get the the tcolorbox centered we can use its center option:
documentclass{article}
usepackage{listings}
usepackage{tcolorbox}
begin{document}
noindenthrulefill % this rule is added to show that the box is actually centered
begin{tcolorbox}[width=0.75linewidth,center]
begin{lstlisting}
alert(123);
end{lstlisting}
boom
begin{enumerate}
item one
item two
end{enumerate}
end{tcolorbox}
noindenthrulefill
end{document}

edited Nov 21 at 19:55
answered Nov 20 at 19:35
Hafid Boukhoulda
977515
977515
add a comment |
add a comment |
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben is a new contributor. Be nice, and check out our Code of Conduct.
Ben is a new contributor. Be nice, and check out our Code of Conduct.
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%2f461004%2fstrange-behaviour-using-center-tcolorbox-listings-and-enumerate%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
1
Welcome to TeX.SE. If you remove
begin{center}andend{center}and instead use{centering.... }%the problem is resolved. Plus using thecenterenvironment is adding additional vertical space -- which is usually not desired. See When should we use begin{center} instead of centering?.– Peter Grill
Nov 20 at 18:11
What's the
centerenvironment supposed to do? Thelstlistingenvironment will use the whole text width anyway.– egreg
Nov 20 at 18:33
Why using the
begin{center} ... end{center}environment or thecenteringcommand while we could simply use thetcolorboxenvironment with thecenteroption?begin{tcolorbox}[center] ... end{tcolorbox}– Hafid Boukhoulda
Nov 21 at 19:50