TeX - LaTeX Asked by TakingItCasual on January 28, 2021
When using listings
‘s linerange
or firstline
/lastline
, the tcolorbox
shows extra top and bottom padding, and the font is different. Is there a way to fix this, or is this a bug with tcolorbox
that should be reported/fixed?
MWE:
documentclass{article}
begin{filecontents*}[overwrite]{test.txt}
line 1
line 2
line 3
end{filecontents*}
usepackage{listings}
usepackage[listings, xparse]{tcolorbox}
tcbset{listing only, sharp corners, top=0pc, bottom=0pc, left=0pc, right=0pc}
%lstset{basicstyle=smallttfamily} % Partially fixes the font difference?
tcbset{listingsstyle/.style={listing engine=listings}}
NewTCBListing{cmd}{ O{} }{listingsstyle, #1}
NewTCBInputListing{cmdinput}{ m O{} }{listing file={#1}, listingsstyle, #2}
begin{document}
begin{cmd}[title={Cmd environment}]sample textend{cmd}
cmdinput{test.txt}[title={Cmd input command (full)}]
cmdinput{test.txt}[title={Cmd input command (partial)},listing options={linerange={2-3}}]
end{document}
Output:
You have not specified a style for the listing options.
"This removes all options for the listings package. This includes the tcblisting standard style tcblatex and the encoding presets. Use this option, if you want to set the listings options outside of tcblisting, e.g. globally in the preamble."
as written on page 314 of the tcolorbox manual. So if you add style=tcblatex
it works as you would expect it.
MWE based on your code
documentclass{article}
begin{filecontents*}[overwrite]{test.txt}
line 1
line 2
line 3
end{filecontents*}
usepackage{listings}
usepackage[listings, xparse]{tcolorbox}
tcbset{listing only, sharp corners, top=0pc, bottom=0pc, left=0pc, right=0pc}
%lstset{basicstyle=smallttfamily} % Partially fixes the font difference?
tcbset{listingsstyle/.style={listing engine=listings}}
NewTCBListing{cmd}{ O{} }{listingsstyle, #1}
NewTCBInputListing{cmdinput}{ m O{} }{listing file={#1}, listingsstyle, #2}
begin{document}
begin{cmd}[title={Cmd environment}]sample textend{cmd}
cmdinput{test.txt}[title={Cmd input command (full)}]
cmdinput{test.txt}[title={Cmd input command (partial)},listing options={style=tcblatex, linerange={2-3}}]
end{document}
Answered by Nico on January 28, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP