Everyone knows the problem, in Latex a figure or table takes the whole width of a page. Even though you can have several figures/tables next to each other (see posts on minipage and subfigure), with none of these techniques it is possible to have floating text around a figure or table.
Here is how you can do it nicely and easily:
You need to include the floating – figure package in your document:
\usepackage{floatflt}
as well as the graphics package if you want to use figures:
\usepackage{graphics}
Code stub figure:
Similar to the usual figure environment, we first need to open a new floating-figure environment and can than include the image in the document.
\begin{floatingfigure}[lrp]{width}
\centering
\includegraphics{image.jpg}
\caption{fig:default}
\label{fig:figlabel}
\end{floatingfigure}
Captions and labels can be used in the same way as in the figure environment.
Either of the optional arguments is used:
l
: left-hand sided figure
r
: right-hand sided figure
p
: left for even, right for odd page numbers.
The width-argument indicates the space to be taken by the figure.
Tip: Instead of an absolute width value, make it relative by using a fraction of the textwidth or columnwidth. E.g.
0.5\textwidth
Code stub table:
The main difference of the floating table to the floating figure environment is the second argument. Here we are not indicating the width, but passing the whole table as argument. This is probably necessary to determine the size of the table, which cannot be adjusted by the writer, but is determined by the table itself.
\begin{floatingtable}[l]{
\begin{tabular}{|c|c|}
\hline
...&...\\
...&...\\
\hline
\end{tabular}}
\caption{default}
\label{tab:tabref}
\end{floatingtable}
Hint: The only way to reduce the width taken by the table is to reduce the font size. E.g.
\begin{footnotesize}
\begin{floatingtable}
...
\end{footnotsize}
Check this post for an introduction to tables.
James C.
Thank you! I’ve wanted an easier way to do this in LaTeX.
sumidiot
I’ve also done similar things without much trouble using the ‘wrapfig’ package.
The best blog about Caption Writers » Blog Archive » ‘caption writer’ on the web
[…] http://texblog.wordpress.com/2008/04/14/floating-text-around-figuretable/… which cannot be adjusted by the writer, but is determined by the table itself. begin{floatingtable}[l]{ Jetstar begin{tabular}{|c|c|} hline …&…\ …&…\ hline end{tabular}} caption{default} label{tab:tabref} end{floatingtable} … […]
M
Thanks a lot for the tip!
Alex
Nice post about floating enviroment.
Thanks,
S. C. Rai
Its a great help for managing figure and table side by side
Dan Murray
good tutorial.
Is there anyway to put text on top of images? I am trying to create a magazine using latex.
tom
Placing “caption” before “includegraphics” should do the trick:
Best, Tom.
Jeff Martens
This was very helpful–thanks! The one piece I was missing was how to install floatflt.sty on Ubuntu 10. Clear instructions are at http://intertwingly.net/blog/2010/04/22/Restoring-floatflt-sty
fabian schulz
i did everything es describes above but whatever size i give to the image i get an overfull \hbox and no figure is displayed in the output – can somebody help me?
tom
Fabian, could you provide some sample code that illustrates the problem. Thanks, Tom.
Abhinav Gaur
IS there any way to put a Figure and text ADJACENT to each other.
e.g.
Imagine I have a 2×1 matrix, now in the element (1,1) of the matrix I want to insert an image and in the element (1,2), I want to insert some text.
tom
Hi there,
The minipage environment is probably what you are looking for. Hope it helps, Tom.
Guillaume Belanger
Hi,
After various trials, I find that wrapfig works better: http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Wrapping_text_around_figures
tom
Thanks for the link. Best, Tom.