Include data from a .txt verbatim

In addition to listings, the fancyvrb package is equally suitable for this purpose.

This package provides the \VerbatimInput command (similar to \verbatiminput), which can be customised using various parameters (e.g., reducing font size).

\documentclass{article}

\usepackage[dvipsnames]{xcolor}

\usepackage{fancyvrb}

% redefine \VerbatimInput
\RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}%
{fontsize=\footnotesize,
 %
 frame=lines,  % top and bottom rule only
 framesep=2em, % separation between frame and text
 rulecolor=\color{Gray},
 %
 label=\fbox{\color{Black}data.txt},
 labelposition=topline,
 %
 commandchars=\|\(\), % escape character and argument delimiters for
                      % commands within the verbatim
 commentchar=*        % comment character
}

\begin{document}

\VerbatimInput{data.txt}

\end{document}

enter image description here

Notes:

  • specifying | and (/) as the escape character and argument delimiters means these symbols cannot appear as part of the verbatim text (or in this case, the contents of data.txt);
  • the line of asterisks in data.txt was removed by specifying * as the comment character (similar to % in LaTeX);
  • the line highlighted in green was obtained by modifying it as follows:

(|color(Green) 8 400.519E-33 -12. 17.1429 27.3494E+03)


Thanks to egreg.

Adding

\usepackage{verbatim}

to the preamble, and using

\verbatiminput{<file path>}

to input, does the tick!


You can also make the font size smaller in a verbatim environment by making a new environment I call \verbatimprog, which uses the \footnotesize font size.

Place the lines below in the preamble (before \begin{document}):

 \DefineVerbatimEnvironment%
      {verbatimprog}%
      {Verbatim}%
      {fontsize=\footnotesize}%

Then, to use the new environment, say

\begin{verbatimprog}

(your program output here)

\end{verbatimprog}

Tags:

Input