Monthly Archives: May 2010

Dynamic scaling of figure width

I recently found the following Latex code snippet in the web and thought it is worth to share it with you. If you have large figures that stretch over the linewidth or textwidth, whatever you prefer and want to reduce them automatically, the following piece of code will do it for you:

\usepackage{graphicx}
\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother


\begin{document}

\includegraphics[width=\ScaleIfNeeded]{Bild}

\end{document}

This piece of code was published here under the GNU Free Documentation License, Version 1.2.


Wrap text around figures and tables

Latex provides the wrapfig package which lets you wrap text around figures. In not only saves place, but also embeds the figure nicely into your text.

Add the wrapfig package in your preamble:

\usepackage{wrapfig}

And place the figure where you want to have it:
\begin{wrapfigure}[1]{2}[3]{4}
...
\end{wrapfigure}

and similarly for tables:
\begin{wraptable}[1]{2}[3]{4}
...
\end{wraptable}

  1. Number of lines (optional)
  2. “r” for right and “l” for left figure placement.
  3. Overhang (optional)
  4. Width to be reserved.

Example:
\begin{wrapfigure}[6]{r}[\columnwidth+\columnsep]{9cm}
\centering
\includegraphics[width=0.3\textwidth]{figure.jpg}
\caption{My figure.}
\label{fig:myfig}
\end{wrapfigure}

To reduce the vertical space on top of the figure, between the figure and the caption as well as below the caption, use:
\vspace{-10pt}
wherever necessary.

Finally, with the wrapfig package it is also possible to embed a figure/table into text that is structured into multiple columns, where the figure stretches over several columns.  This is a bit more tricky to achieve and a manual can be found in the wrapfig documentation.


Latex letter signature as image

Trying to place an image (scan of one’s signature) between the closing and the name in a letter will unfortunately not result in a nice formatting. Latex automtically adds some space for a manual signature between the closing and the printed name. This space will not automatically disappear if you place your signature as an image there. Neither will it disappear if you place the image directly in the \signature declaration. But, as you might have guessed, there is a work-around:

Remove the \signature{Your name} declaration (see this sample letter) and just replace the \closing{Yours Faithfully,} by:

\closing{Yours faithfully, \\
\fromsig{\includegraphics[scale=1]{signature.jpg}} \\
\fromname{Your name}
}

For more information, consider the documentation.


Excluding items from list-of-figures / list-of-tables

Imagine you have an appendix chapter that contains a whole set of figures, but you don’t want them to show up in the list of figures.

The caption package does the trick for you:

\usepackage{caption}

and then use

\captionsetup[figure]{list=no}

to exclude figures from the LOF from that point onwards. Switching it on again can obviously be done using:

\captionsetup[figure]{list=yes}

Similarly, you can exclude/include tables using these commands:

\captionsetup[table]{list=no}
and
\captionsetup[table]{list=yes}


Follow

Get every new post delivered to your Inbox.

Join 316 other followers