When I use the listings package with frame in my code the frame "breaks" when the page ends and it is open in the end of the page. I want the frame to be complete with four sides and continue in the next page again with all four frame sides complete. How can I do this? Why does the frame "breaks"?
1 Answer
It is possible with tcolorbox
.
\documentclass{article}
\usepackage{tcolorbox,listings}
\usepackage[textheight=2in]{geometry}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt
}
\tcbuselibrary{listings,skins,breakable}
\newtcblisting{mycode}{
arc=0mm,
top=0mm,
bottom=0mm,
left=3mm,
right=0mm,
width=\textwidth,
boxrule=1pt,
colback=blue!20,
listing only,
listing options={style=mystyle},
breakable
}
\begin{document}
\begin{mycode}
abc def {
xyz
some
again some
Some again
\end{mycode}
\end{document}
The advantage is, with tcolorbox
, you can do lot of customisations.
-
Thank you for your answer! I will check if it solves my problem.– AdamCommented Apr 3, 2014 at 23:07
-
I tried it and it works! The only "problem" is that you have to specify how big you want the box to be although I would prefer to adjust automatically with the length of the code.– AdamCommented Apr 4, 2014 at 14:43
-
@Adam There is
hbox
option but it won't allow you to break across pages. You can try withvarwidth
and post a new question on that. :)– user11232Commented Apr 4, 2014 at 14:45 -
I think that someone can use a box as long as the page for the worst case. This seem to solve the previous problem I mentioned!– AdamCommented Apr 4, 2014 at 14:53
-
Also why there is space at the top and at the bottom of the box? How can I make it disappear?– AdamCommented Apr 4, 2014 at 15:28
listings
directly.