1

I am trying to achieve the following:

I have text material which is to be put in verbatim form. This material also has some mathematics, so I am using the alltt package. This text needs to be in a single column table, which should be framed, for which I am using the mdframed package.

The MWE is as below

\documentclass{article}
\usepackage{alltt}
\usepackage{mdframed}
\begin{document}
\begin{table}
\begin{mdframed}
\begin{alltt}
\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
\end{alltt}
\end{mdframed}
\caption{This is the caption}
\end{table}

\end{document}

This produces a table which goes beyond the current page. What is needed is that the table overflows with the outer frame to the next page. I tried to use the longtable but it seems alltt does not like it.

Any other method of achieving this alltt inside a boxed table which can flow across pages would also be okay.

1 Answer 1

1

A table is a float and it won't break across pages. And if you use a longtable, it too can't break across the pages inside the same row (and you have only one row). What to do? Don't use them. If you need a caption use \captionof{table}{caption...} from either caption or capt-of packages.

 \documentclass{article}
\usepackage{alltt,capt-of}
\usepackage{mdframed}

\begin{document}
\bgroup
\captionof{table}{This is the caption}
\egroup
\begin{mdframed}[skipabove=\topskip,skipbelow=\topskip]
\begin{alltt}
\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
\end{alltt}
\end{mdframed}
\end{document}

enter image description here

On ther other hand, there is also tcolorbox that offer lot more. Here is an example for your case.

\documentclass{article}
\usepackage{alltt,capt-of}
\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\definecolor{light-gray}{gray}{0.95}


\begin{document}
%\begin{table}
\bgroup
\captionof{table}{This is the caption}
\begin{tcolorbox}[width=\linewidth,
    enhanced jigsaw,
    boxrule=0.4pt,
    colframe=black,
    colback=white,%light-gray,  
    breakable,sharpish corners
    ]
\begin{alltt}
\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
        \textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();\textbf{OOS()}
begin
preprocess the image \emph{m}.
        data\_normalize(\emph{data}, \emph{method});
        kmeans(data, n);
        kmedoid(data, n);
        fcmeans(data, n);
        validity(result, data, param);
        object();
\end{alltt}
\end{tcolorbox}
\egroup


\end{document}

enter image description here

4
  • This works fine as required. But if I place the captionof at the beginning (which I want) instead of the end (like in the example above), it doesn't work properly. The caption remains on one page while the mdframed is moved to the next without breaking. Any workaround for placing the caption at the start rather than at the end?
    – Damitr
    Jan 23, 2015 at 3:12
  • I get the following error while running the above code ! LaTeX Error: Unknown option many' for package tcolorbox'. ... l.755 \ProcessOptions* Also after letting this pass I get few more errors! Package pgfkeys Error: I do not know the key '/tcb/enhanced jigsaw' and I am going to ignore it. Perhaps you misspelled it. ! Package pgfkeys Error: I do not know the key '/tcb/breakable' and I am going to ignore it. Perhaps you misspelled it. The resulting frame does not break across pages.
    – Damitr
    Jan 23, 2015 at 13:26
  • 1
    @Damitr Use \usepackage{tcolorbox} \tcbuselibrary{breakable,skins} instead of \usepackage[many]{tcolorbox} (see the edited answer). If this doesn't work, you have to update your tcolorbox.
    – user11232
    Jan 23, 2015 at 13:39
  • The first error has gone with the changes in the preamble. But the remaining two still persist. I remove the enhanced jigsaw and sharpish corners options and it woks fine now. Thanks for the help.
    – Damitr
    Jan 23, 2015 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .