Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For my thesis, I have written a computer program that reads in a parameter file. I want to show the parameter file in my thesis but am not sure what the best way to go about this is.

Ultimately, I want to show the parameter file in some sort of typewriter-like font (say Courier) with a caption. I would also like to show the line numbers for the parameter file. What's the best way to do this?

I know how to do line numbers and change the font, but I don't know how to give a caption to some random text that is not really a figure.

Aside: should the parameter file be shown as a "figure" or a "table"?

share|improve this question
add comment

3 Answers

You can easily treat your parameter file as a standard figure or a table; in the third example code below I used this approach.

To add captions outside floating environments, you could use the \captionof command from the caption (or capt-of) package; in the last example code below I used this approach.

To have automatic number line, monospaced font and listing-like feeling, one option would be to use the highly customizable listings package; a little example:

\documentclass{article}
\usepackage{listings}
\lstset{% general command to set parameter(s)
basicstyle=\small\ttfamily,% print whole listing small and with monospaced font
numbers=left% number lines to the left
}

\begin{document}

\begin{lstlisting}[caption={Parameter file used elsewhere}]
column1a column2a column3a
column1b column2b column3b
\end{lstlisting}

\end{document}

enter image description here

Another option could be the fancyvrb package;

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}

\begin{Verbatim}[frame=lines,label={A parameter file used elsewhere},numbers=left,numbersep=10pt]
column1a column2a column3a
column1b column2b column3b
\end{Verbatim}

\end{document}

enter image description here

If you want to treat your parameter file as a table (or a figure), you can wrap the Verbatim environment inside a table (or a figure) environment; notice that this implies that now you are dealing with a floating object:

\documentclass{article}
\usepackage{fancyvrb}

\begin{document}

\begin{table}
\caption{A parameter file used elsewhere}
\begin{Verbatim}[numbers=left,numbersep=10pt]
column1a column2a column3a
column1b column2b column3b
\end{Verbatim}
\end{table}

\end{document}

enter image description here

Using \captionof you can give your parameter list a caption such as those used for the figure or the table environment, but without using a floating environment. A little example:

\documentclass{article}
\usepackage{caption}
\usepackage{fancyvrb}

\begin{document}

\begin{center}
\captionof{table}{A parameter file used elsewhere}
\begin{Verbatim}[numbers=left,numbersep=10pt]
column1a column2a column3a
column1b column2b column3b
\end{Verbatim}
\end{center}

\end{document}

enter image description here

or

\documentclass{article}
\usepackage{caption}
\usepackage{fancyvrb}

\begin{document}

\noindent\begin{minipage}{\linewidth}
\captionof{table}{A parameter file used elsewhere}
\begin{Verbatim}[numbers=left,numbersep=10pt]
column1a column2a column3a
column1b column2b column3b
\end{Verbatim}
\end{minipage}

\end{document}

to prevent page breaks inside the environment.

share|improve this answer
    
Thanks for that great response. I like the last example... However, I'm seeing my text get split across different pages. Is it possible to keep the text together without splitting across pages? Thanks. –  Flux Capacitor Mar 26 '12 at 3:59
    
@FluxCapacitor: sure. See my updated answer. –  Gonzalo Medina Mar 26 '12 at 5:06
    
I would prefer solution using listings. IMHO pieces of code/configuration files/... should be floating, and the name "Listings" seems to be the most proper one. Besides the listings package, one can creat new type of float using the float package as well. –  tohecz Mar 26 '12 at 6:44
add comment

The simplest way to show your parameter file is just to place everything in a verbatim environment. You get a fixed width font automatically.

\begin{verbatim}
numbers and text
\end{verbatim}

Figure and table environments are generic and really only differ in how the captions are titled, e.g., Figure 3.1 or Table 3.1 and what shows up in the listoffigures or listoftables So the choice of where to put your code fragments should be based on that.

There are other packages (like fancyvrb) that might be better suited to your particular problem if you want auto-numbering of lines or other features.

share|improve this answer
add comment

If I understand your question correctly, you're looking to automate the creation of certain table and figure floats that (i) should have their contents set in a typewriter (aka "monospaced") font automatically and (ii) otherwise share all features of the "regular" table/figure environments.

One way to achieve this is to define two new environments called, say, twtable and twfigure (short for typewriter-table and typewriter-figure), as follows:

\makeatletter
\newenvironment{twtable}%
    {\renewcommand\familydefault\ttdefault \selectfont%
     \@float{table}}
    {\end@float}
\newenvironment{twfigure}%
    {\renewcommand\familydefault\ttdefault \selectfont%
     \@float{figure}}
    {\end@float}
\makeatother

If you insert this code snippet into your document's preamble, all twtable and twfigure floats will be typeset in typewriter font but otherwise be indistinguishable from table and figure floats.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.