Graphics, Figures & Tablesputting code in a box with figure caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

putting code in a box with figure caption

Post by carol »

I have a piece of code that I want to integrate into my tex document. I have used \verbatiminput to include the code into my document, but I would like to put it in a box and use figure caption to explain it. How could I do this? Does the figure caption number would follows other figure caption created by \begin{fgure}?

Note that I use kile.

Cheers,

Carol

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

-Robin-
Posts: 31
Joined: Tue May 20, 2008 3:07 pm

putting code in a box with figure caption

Post by -Robin- »

Use the listings package
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

Re: putting code in a box with figure caption

Post by carol »

How about if it is not a code but the output of a program or just a text file?

Moreover, the captions of the listing are independent of floats. I want the opposite that the captions of these pieces would follow floats' caption.

Also, note that there are some lines that exceed the width of the page so they should be adjusted

Any suggestions?
-Robin-
Posts: 31
Joined: Tue May 20, 2008 3:07 pm

putting code in a box with figure caption

Post by -Robin- »

carol wrote:How about if it is not a code but the output of a program or just a text file?
No problem for the listing package
carol wrote:Moreover, the captions of the listing are independent of floats. I want the opposite that the captions of these pieces would follow floats' caption.
I don't really understand what you mean. If you're saying that the listing package uses his own counter and name for the captions, you can easily adjust it (its explained in the documentation of the listing package)
carol wrote:Also, note that there are some lines that exceed the width of the page so they should be adjusted
Automatic line breaking is an option of the listing package, as explained in the documentation of the package
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

Re: putting code in a box with figure caption

Post by carol »

Hi Robin,
Thanks for your reply. Actually, I found no information how it is possible to have the same counter for listings captions and floating caption. I have defined a command for floating captions \newcommand*\mycaption[2]{\caption[#1]{#1 #2}}, how could I use it as key value for \lstinputlisting[]?

Look forward to your reply,

carol
Post Reply