Text Formatting ⇒ Referencing a Code
Referencing a Code
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
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Referencing a Code
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
Referencing a Code
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...
Follow howtoTeX on twitter
Referencing a Code
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