Monday, June 12, 2006

Latex snippets: Add image, wrap long lines in table

Using Latex to create an interim report to submit for my FYP. Its pretty useful, though today I got caught in a weird error. When trying to include an image, using \includegraphics, it showed me:
Undefined control sequence. \includegraphics


Its pretty obvious now, that this is a valid instruction in Latex. After googling I found out that:

  1. You need to add \usepackage{graphicx} in the preamble, for this instruction to work.

  2. You need to provide complete path of the image file

  3. Don't include the extension of the image. Latex will search for it automatically. Not sure the sequence, but, I believe its .png, then .gif, ...

My code:
\begin{figure}
\centering
\includegraphics[width=150mm]{/home/username/report/fuse}
\end{figure}


Another interesting thing was to use tables which can word wrap long lines without cropping the table. I couldn't find any working example of this online, so putting it here, for reference:

\begin{tabular}{|c|p{5cm}|p{5cm}|}
topic & long line 1 & long line 2 \\end{tabular}

6 comments:

Heiko said...

The path to the image file does not necessarily have to be absolute; it can also be a path relative to the main latex source file.

punit said...

Thanks for the table example. Saved my day! :)

waker said...

thnx for the line wrapping example. was searching for it for last 3 days.

Greg Taylor said...

Yep, the word-wrapping code was great for me. Thanks!

billynomates said...

Word wrapping good for me too! Cheers

Markus said...

Currently writing a masters thesis, I was so fustrated by word wrapping in tables! Thank you.