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.

This code for example:

\begin{verbatim}
int main()
{
}
\end{verbatim}

How to add a label below it to be referenced?

int main()
{
}
  [code 1]
share|improve this question
4  
look for package listings. It can do it for you –  Herbert Sep 26 '12 at 9:02
    
Thanks! It works. –  chyx Sep 26 '12 at 9:06
add comment

2 Answers

up vote 3 down vote accepted

without option float there is a better spacing here.

\documentclass{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[language=C,frame=single,caption=My caption here,label=code1]
int main()
  {
  }
\end{lstlisting}

From code~\ref{code1} it can be seen clearly....

\end{document}
share|improve this answer
add comment
\documentclass{article}
\usepackage{listings}

\begin{document}

\lstset{language=C,frame=single}

\begin{lstlisting}[float,caption=My caption here,label=code1]
int main()
{
}
\end{lstlisting}

From code~\ref{code1} it can be seen clearly....

\end{document}
share|improve this answer
    
Why community wiki? –  ℝaphink Sep 26 '12 at 14:06
    
@Raphink The OP already solved his problem using Herbert's comment. I just wanted to reduce the unanswered by 1. ;) –  Harish Kumar Sep 26 '12 at 14:08
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.