In my tex I have this command:

\captionof{lstlisting}{HTTP Request where string was found}

which generate 1.2 value

when I use ref command, like

The listings \ref{lst:use_case_ip}

I've got 1.4.1 value... that's completely wrong

where is my mistake?


Your mistake is that \caption is responsible from generating the anchor that the \label, \ref mechanism will pick for cross-referencing and you are using label before assigning a caption.

Instead of \captionof, use the caption key; otherwise. the wrong string will be picked for cross-referencing:

\lstinputlisting[breaklines=true,caption={HTTP Request where string was found},label={lst:use_case_ip}]{ch5/code/get.txt}

You can control the position of the caption using the captionpos key (possible values: b for bottom, t for top):

  • nice, it works. but It put the caption above the listing... is there an attribute to put it after the listing? – CDominik Oct 10 '15 at 14:51
  • @DomenicoChiarito Sure: captionpos=b. – Gonzalo Medina Oct 10 '15 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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