I am (ab)using a framed listings environment include an enumeration environment (by escaping to latex). This compiles fine but in the resulting pdf the frame around the listing is interrupted.
Minimal working example:
\documentclass{report}
\usepackage[english]{babel}
\usepackage{float}
\usepackage[margin=10pt,font=small,labelfont=bf,justification=centering]{caption}
\usepackage{listings}
\renewcommand{\lstlistingname}{Box}
% Setup for listings:
\lstset{extendedchars=true,
tabsize=3,
frame=single,
frameround=tttt,
showspaces=false,
framesep=10pt,
boxpos=c,
float=h,
captionpos=b,
escapechar=\%
}
\lstdefinestyle{Normaltext}{language=,numbers=none,basicstyle=\normalfont}
\lstnewenvironment{textbox}[2]
{%
\centering
\minipage{0.9\textwidth}
\lstset{style=Normaltext,label=#1,caption=#2}
}
{%
\endminipage
\endcenter
}
\begin{document}
\begin{textbox}{box:somelabel}{some caption}
%{Test 1 2 3, here comes the enumeration:
\begin{itemize}
\item item 1
\item item 2
\item item 3
\item item 4
\end{itemize}
}%
\end{textbox}
\end{document}
This produces something like this:

Any ideas how I can avoid that the frame is interrupted?
Or maybe somebody can suggest a better alternative to abusing listings for putting plain latex text in a frame box, because that's all I really wanted. Basically what I want to achieve is this:
- I want 3 types of "objects" in my document: figures, tables and boxes.
- Figures have the "Figure" label and are listed in the listoffigures.
- Tables have the "Table" label and are listed in the listoftables.
- Similarly I want boxes to have the "Box" label and be listed in a listofboxes (I was planning to use listoflistings for this).
- Boxes can either contain source code (using listings package) or plain latex text, but either way they should have the same rounded frame around them and be centered on the page and cover 90% of textwidth (I was using minipage for this, as you can see in my code).
\listoflistings... – Seamus Aug 17 '11 at 13:31style=1tostyle=3, that might work to have the lines show up. I've updated the example to include captions and a reference mechanism built into the environments, as per your original example. – Seamus Aug 17 '11 at 13:44style=1but Try addinglinewidth=1ptto the list of options: maybe it's your pdf viewer failing to resolve the thin default line... Or try a different PDF viewer or try zooming in... – Seamus Aug 17 '11 at 14:16\DeclareCaptionType{boxx}and (re)define the boxx environment afterwards. Simply place\captionsetup{type=boxx}at first line of environment code (this will place the hyperref anchor, if necessary, and will initialize the use of \caption) and do the captions with\caption. – Aug 17 '11 at 14:26mdframedlines not showing up. It might have something to do with not having the right version of tikz. In any case, it doesn't really relate to the subject of this current question. – Seamus Aug 17 '11 at 14:46needspaceto keep the caption with the box. – Seamus Aug 17 '11 at 16:32captionsetupinside themdframed? – Seamus Aug 17 '11 at 16:32boxctr? IMHO there is no need for it, placing the \label after the caption should be sufficient:\gdef\boxxcaption{\caption{#2}\label{#1}}. – Aug 17 '11 at 16:44\captionsetupinsidemdframed, the caption will not work since it will be typeset outside themdframedenvironment. Maybe a \nopagebreak will help instead? Unfortunately I do not have much time now, will play around with it tomorrow... – Aug 17 '11 at 16:49\newenvironment{Boxx}[2]{% \gdef\boxxcaplab{\caption{#2}\label{#1}} \captionsetup{type=boxx} \begin{mdframed}[% linewidth=1pt, linecolor=black, innerlinecolor=black, middlelinecolor=black, outerlinecolor=black, roundcorner=10pt, leftmargin=.05\textwidth, rightmargin=.05\textwidth, skipabove=.7\baselineskip, skipbelow=.7\baselineskip] \nopagebreak }{ \end{mdframed} \boxxcaplab }But this still puts the hyperref anchor on the previous page in case of pagebreak. – Matthias Aug 17 '11 at 16:50\nopagebreakshould be placed right before\begin{mdframed}. – Aug 17 '11 at 16:54\newenvironment{framed}[2]{% \gdef\caplab{\caption{#2}\label{#1}} \pagebreak[2] \captionsetup{type=framedbox} \nopagebreak \begin{mdframed}...The
– Matthias Aug 17 '11 at 17:41\pagebreak[2]suggests a pagebreak to happen before\captionsetup. This fixes the problem of the hyper anchor remaining on the previous page, and as far as my example goes it does not cause unwanted "mid-page" pagebreaks. Do you guys think this is a proper solution?\caption@freezeand\caption@defrostinstead of\boxxcaptionso ordinary\captioncan be used (with optional argument), and\ContinuedFloatand\captionsetupwill work insideboxx, too. I uploaded it to http://latex.sommerfeldt.f-m.fm/test.tex Maybe some of the stuff used there is of any use for you? – Aug 17 '11 at 18:38\captionwith optional argument. However, the downside seems to be that when using freeze/defrost I can no longer define labels in the boxx. I wanted to do this to refer to enumberation items. I already tried to pass the label as an argument to boxx again (and set it with \label inside the env definition, like seamus did before), but that doesn't fix it. I can only define labels in th boxx when I don't use freeze/defrost. Any idea on how to have both "in-boxx" labels and\caption? – Matthias Aug 17 '11 at 22:19\begin{boxx}{\caption[short]{long}\label{box:example}} ... \end{boxx}. In the renewnvironment I store #1 as\boxxcaplabwith gdef and call it in the end part. This allows me to use \caption with optional arg, while still having labels in the boxx. Example: http://brussense.be/temp/Boxx.tex PDF: http://brussense.be/temp/Boxx.pdf – Matthias Aug 17 '11 at 23:14\caption@freezeneeds to redefine\labelso it can utilize\captionand\labelon\caption@defrost. You could include\let\Label\labeljust before\caption@freezeand use\Labelfor labeling your equations. (Of course this is only a workaround, will try to fix that for thecaptionpackage v3.2b right now...) – Aug 18 '11 at 05:44\let\Label\labelfor now. Good luck fixing it in the package. Will you let us know on this page when it is done? – Matthias Aug 18 '11 at 07:44\labelso it takes an optionaltypeargument (this is a way to customize reference labels, see section 8 of the cleveref documentation). But when I use such a\label[type]{...}inside one of my boxxes this does not work. Even when not using freeze/defrost and\let\Label\label. – Matthias Aug 18 '11 at 13:06\let\Label\label? – Matthias Aug 18 '11 at 13:26\caption@freezeand\caption@defrost(well, at least as long as they don't have an optional argument ;-)) If they don't, please drop me an e-mail with an example document showing the problem. (You'll find my e-mail address in the caption package documentation.) – Aug 18 '11 at 16:34\caption? – Matthias Aug 18 '11 at 17:09\caption,\sectionetc.) defines a "dog tag" (called\@currentlabel), and\labelputs this tag into the aux file. So I simply set this tag to a special value when using\captioninside such environment. My version of\labelchecks if the tag is set to this special value or not. If not, the ordinary\labelcode will be used. – Aug 19 '11 at 08:25