如何调整图形环境中的 verbatimtab 环境的大小(也许使用包 adjustbox)?

如何调整图形环境中的 verbatimtab 环境的大小(也许使用包 adjustbox)?

如何调整图形环境中的 verbatimtab 环境的大小(可能使用包adjustbox)?我有一些类似以下的代码:

\begin{figure}[htb]
    \centering
    \begin{verbatimtab}
                2012-12-03
                - thesis
                + relationship
                / - go to space
                / - #shopping notebook
                \ - jazz in The 78
                X - sleep at a reasonable time
    \end{verbatimtab}
    \caption{illustration of simple list}
    \label{fig:list_1}
\end{figure}

verbatimtab 环境由包提供moreverb。在表格环境中,adjustbox可以使用包;表格环境可以包含在 adjustbox 环境中,如下所示:

\begin{table}[H]
    \centering
    \begin{adjustbox}{width=\hsize, totalheight=\textheight, keepaspectratio}
    \begin{tabular}{lll}
        % table content
    \end{tabular}
    \end{adjustbox}
\end{table}

如何对表格环境中的表格环境进行类似重新缩放,以适应图形环境中的逐字表环境?

下面是一个最小的工作示例,应进行修改,以便逐字文本重新缩放以适合页面的可用文本区域 (\hsize):

\documentclass{article}
% page margins
    \usepackage[
        left=5cm,
        right=5cm,
        top=5cm,
        bottom=5cm
    ]{geometry}
% rescaling
    \usepackage{adjustbox}
% verbatim
    \usepackage{moreverb}
% table handling
    \usepackage{float}
    \restylefloat{table}
% custom figure and table caption prefixes
    \renewcommand{\figurename}{figure}
    \renewcommand{\tablename}{table}

\begin{document}

\begin{table}[H]
    \centering
    \begin{adjustbox}{width=\hsize, totalheight=\textheight, keepaspectratio}
    \begin{tabular}{lll}
        \hline
        \hline
        a&b&c\\
        \hline
        \hline
    \end{tabular}
    \end{adjustbox}
\end{table}

\begin{figure}[htb]
    \centering
    \begin{verbatimtab}
        2012-12-03
        - thesis
        + relationship
        / - go to space
        / - #shopping notebook
        \ - jazz in The 78
        X - sleep at a reasonable time
        2013-10-24T1629
        - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    \end{verbatimtab}
\caption{illustration of simple list}
\label{fig:list_1}
\end{figure}

\end{document}

答案1

BVerbatim您可以使用( \usepackage{fancyvrb}) 来尊重制表符,或者通过将其封闭在具有较大最大宽度的环境verbatimtab中( )来实现。varwidth\usepackage{varwidth}

\documentclass{article}
% page margins
\usepackage[
  left=5cm,
  right=5cm,
  top=5cm,
  bottom=5cm
]{geometry}
% rescaling
\usepackage{adjustbox}
% verbatim
\usepackage{fancyvrb,moreverb,varwidth}

\setlength{\parindent}{0pt} % just for the example

\begin{document}


X\dotfill X

\begin{adjustbox}{width=\hsize, totalheight=\textheight, keepaspectratio}
\begin{BVerbatim}[tabsize=8]
2012-12-03
    - thesis
    + relationship
    / - go to space
    / - #shopping notebook
    \ - jazz in The 78
    X - sleep at a reasonable time
2013-10-24T1629
    - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{BVerbatim}
\end{adjustbox}

\bigskip

\begin{adjustbox}{width=\textwidth}
\begin{varwidth}{.5\maxdimen}
\begin{verbatimtab}
    - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{verbatimtab}
\end{varwidth}
\end{adjustbox}
\end{document}

(请注意,这里没有保留标签,但我将它们保存在文件中)。

在此处输入图片描述

答案2

我建议采用一种完全不同的方法。这种方法仍然遵循源代码中的换行符以及空格,只是太长的行会像普通文本一样换行,在逐字文本中也是如此。

\documentclass{article}
% give some stretch to tt font
\def\givesomestretch{%
\fontdimen2\font=0.33333\fontdimen6\font
\fontdimen3\font=0.16666\fontdimen6\font
\fontdimen4\font=0.11111\fontdimen6\font
}%

% allows breaking of long lines (linebreak in source will still be obeyed)
% As moreverb is loaded later we move this to \AtBeginDocument

\makeatletter
\AtBeginDocument{\let\ORIG@verbatim@font\verbatim@font
                 \def\verbatim@font{\ORIG@verbatim@font\givesomestretch}%
                 \def\@xobeysp{\leavevmode\ }%
}
\makeatother

% page margins
    \usepackage[
        left=5cm,
        right=5cm,
        top=5cm,
        bottom=5cm
    ]{geometry}
% rescaling
    \usepackage{adjustbox}
% verbatim
    \usepackage{moreverb}
% table handling
    \usepackage{float}
    \restylefloat{table}
% custom figure and table caption prefixes
    \renewcommand{\figurename}{figure}
    \renewcommand{\tablename}{table}

\begin{document}\thispagestyle{empty}

\begin{table}[H]
    \centering
    \begin{adjustbox}{width=\hsize, totalheight=\textheight, keepaspectratio}
    \begin{tabular}{lll}
        \hline
        \hline
        a&b&c\\
        \hline
        \hline
    \end{tabular}
    \end{adjustbox}
\end{table}



\begin{figure}[htb]
    \centering
    \begin{verbatimtab}
        2012-12-03
        - thesis
        + relationship
        / - go to space
        / - #shopping notebook
        \ - jazz in The 78
        X - sleep at a reasonable time
        2013-10-24T1629
        - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
     \end{verbatimtab}
\caption{illustration of simple list}
\label{fig:list_1}
\end{figure}

\end{document}

输出:

逐字逐句

答案3

这是一个使用 的解决方案verbatimbox。它允许您将逐字材料放在已保存的框中(图形外部),然后在图形环境内重新生成该框。

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
\begin{myverbbox}{\normalverb}
\normalsize\verbatim
\end{myverbbox}
\begin{myverbbox}[\small]{\smallverb}
\small\verbatim
\end{myverbbox}
\begin{myverbbox}[\footnotesize]{\footnotesizeverb}
\footnotesize\verbatim
\end{myverbbox}
\begin{myverbbox}[\tiny]{\tinyverb}
\tiny\verbatim
\end{myverbbox}
\begin{figure}
\centering
  \normalverb\\
  \smallverb\\
  \footnotesizeverb\\
  \tinyverb
\caption{Illustration of a simple list}
\end{figure}
\end{document}

在此处输入图片描述

相关内容