5

How could a verbatimtab environment in a figure environment be resized (perhaps using the package adjustbox)? I have some code something like the following:

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

The verbatimtab environment is provided by the package moreverb. In the case of tabular environments, the package adjustbox can be used; the tabular environment can be contained in an adjustbox environment in a way such as the following:

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

How could something like that rescaling for the tabular environment in the table environment be done for the verbatimtab environment in the figure environment?

Below is a minimal working example which should be modified such that the verbatim text is rescaled to fit within the usable text area of the page (\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}
3
  • You've asked 15 questions before. Have you ever came across the notion of Minimal (non-)Working Example?
    – yo'
    Commented Oct 24, 2013 at 15:16
  • I have come across the notion of a minimal working example. In my question, I do not have a specified problem; I am asking for a suggested approach. So, it's not really possible to illustrate a non-working example in this case. That's why there was no full example given. You can note that two code examples were given to illustrate my thinking. Having said that, I have included a minimal working example of the working concepts I have mentioned. This code could be modified to rescale the verbatim text in a manner such as I suggest.
    – d3pd
    Commented Oct 24, 2013 at 15:35
  • Not with verbatimtab; but you can with BVerbatim from fancyvrb. Or you can enclose verbatimtab in a varwidth environment which is given a very large natural width, say \begin{varwidth}{.5\maxdimen} (requires \usepackage{varwidth})
    – egreg
    Commented Oct 24, 2013 at 16:47

3 Answers 3

3

You can do it with BVerbatim (\usepackage{fancyvrb}) that can be made to respect tabs, or by enclosing verbatimtab in a varwidth environment with a large maximum width (\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}

(Note that tabs are not preserved here, but I had them in the file).

enter image description here

1

I propose an altogether different approach. What this does is to still obey line breaks in the source as well as blank spaces, except that too long lines will be wrapped as for normal text, also inside the verbatim.

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

Output:

verbatimtab

0
1

Here's a solution using verbatimbox. It allows you to place verbatim material in a saved box (outside of the figure), and then regurgitate the box inside the figure environment.

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

enter image description here

You must log in to answer this question.

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