Alltt 内部 mdframed longtable

Alltt 内部 mdframed longtable

我正在尝试实现以下目标:

我有需要以逐字形式呈现的文本材料。该材料还包含一些数学知识,因此我使用了该alltt包。该文本需要放在单列表格中,该列表格应带有边框,为此我使用了该包mdframed

MWE 如下

\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}

这会产生一个超出当前页面的表格。需要的是表格与外框一起溢出到下一页。我尝试使用,longtable但似乎alltt不喜欢。

在可以跨页面流动的盒式表内实现此目的的任何其他方法alltt也是可以的。

答案1

表格是浮动的,它不会跨页。如果你使用 longtable,它也不能在同一行内跨页(并且你只有一行)。该怎么办?不要使用它们。如果你需要标题,请使用或包\captionof{table}{caption...}中的任一包。captioncapt-of

 \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}

在此处输入图片描述

另一方面,还有tcolorbox更多优惠。以下是适合您情况的示例。

\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}

在此处输入图片描述

相关内容