Hi all,
I would like to make a reference to a code listed inside the \begin{verbatim}...\begin{verbatim} environment.
How can I do it? Of course I cannot place the \label command inside the verbatim environment.
Any suggestion?
Thanks in advance
Text Formatting ⇒ Referencing a Code
Referencing a Code
Last edited by frodojedi on Mon Feb 21, 2011 1:28 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Referencing a Code
Hi,
for referencing you probably would like to give a number to that environment. Numbered environments can be produced by using theorem environments.
For code listings I would use the listings package which is able to produce numbered code listings with captions.
Stefan
for referencing you probably would like to give a number to that environment. Numbered environments can be produced by using theorem environments.
For code listings I would use the listings package which is able to produce numbered code listings with captions.
Stefan
LaTeX.org admin
Referencing a Code
If you're refering to a particular line in your verbatim environment, here's how:
Note that the environment is not verbatim but Verbatim. You'll need the fancyvrb package
Code: Select all
\begin{Verbatim}[commandchars=\\\{\},numbers=left,numbersep=2pt]
First verbatim line.
Second line.\label{vrb:Important}
Third verbatim line.
\end{Verbatim}
As I previously shown line~\ref{vrb:Important}, it is...
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
Referencing a Code
Hello,
thanks a lot. I have a problem with the caption when using also a frame.
Actually I am using a template: http://openwetware.org/wiki/LaTeX_templ ... PhD_thesis
When I put the following code I get that the frame is upon the caption.
I am using both \usepackage{listings} and \usepackage{fancyvrb}. When I compile in a new document without the template I don´t get that behavior.
Is there a way to overcome this problem?
Thanks in advance
thanks a lot. I have a problem with the caption when using also a frame.
Actually I am using a template: http://openwetware.org/wiki/LaTeX_templ ... PhD_thesis
When I put the following code I get that the frame is upon the caption.
Code: Select all
\begin{lstlisting}[caption={Example 1},label=lst:example1,frame=single, rulecolor=\color{red}]
\documentclass{article}
\begin{document}
....
\end{document}
\end{lstlisting}
I am using both \usepackage{listings} and \usepackage{fancyvrb}. When I compile in a new document without the template I don´t get that behavior.
Is there a way to overcome this problem?
Thanks in advance
Re: Referencing a Code
Hi I found the solution, I just added \bigskip in the caption after the text