Graphics, Figures & TablesProblem with subfig package in twocolumn environment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Bramschermers
Posts: 1
Joined: Wed May 25, 2011 10:04 pm

Problem with subfig package in twocolumn environment

Post by Bramschermers »

Hey there,

I'm kind of new to this LaTeX thing and I've started out with the subfigure. I've just found out that this has been replaced by the subfig package, so I switched to this. However unlike the subfigure package (which gave me other problems though) it gives me problems with subfloats in a twocolumn environment. My preamble is as follows:

Code: Select all

documentclass[10pt,a4paper,twoside,twocolumn]{article}
 \usepackage[scriptsize,hang]{caption}												      
 \usepackage[margin=1.5cm,tmargin=3cm, bmargin=2cm]{geometry} 
 \usepackage{graphicx}																			  
 \usepackage{fancyhdr}																			  
 \usepackage{multicol}																			   
 \usepackage[square,comma,sort&compress,nonamebreak]{natbib}																	
 \usepackage{subfig}																				
 \usepackage{hyphenat}
 \usepackage{verbatim}																				
 \usepackage{subeqn}                                          
 \usepackage{appendix}																				
 \usepackage[colorlinks=false,pdfborder={0 0 0}]{hyperref}                                 
 \usepackage[nonumberlist,numberedsection,toc]{glossaries}	
And my piece of problematic figure coding is:

Code: Select all

	\begin{figure}
	\centering
			\subfloat[\emph{Photoelectric effect:} Blablablacaption.\label{fig:photo}]{\includegraphics[width=6cm]{./Robert/photo.jpg}}
			\subfloat[\emph{Compton effect:} Blablablacaption2.\label{fig:compton}]{\includegraphics[width=6cm]{./Robert/compton.jpg}}
			\caption{Gamma-ray interaction effects}
			\label{fig:gammarayeffects}
	\end{figure}
The result is the following (screenshot of pdf):

Image

It's clear to see that the image (figure 5) completely falls off the document on the right side, while I was under the impression the subfig package would automatically detect this and put the subfloats under eachother.

What did I do wrong? (I'm sure it's something easy, but I'm a n00b so I apologize in advance ;))

Thanks

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Problem with subfig package in twocolumn environment

Post by sommerfee »

Bramschermers wrote:It's clear to see that the image (figure 5) completely falls off the document on the right side, while I was under the impression the subfig package would automatically detect this and put the subfloats under eachother.
No, the subfig package does not detect this. TeX is handling such things like paragraph breaking etc.

For TeX a \subfloat is simply a box, just like a simple letter, or a \parbox etc. TeX breakes paragraphs into lines by hyphenation, if it can't do hypenation (like with \subfloat boxes), it tries to break the lines at spaces.

So all you need to do is put some space between the \subfloats so TeX can do an automatic line break here, if necessary.

Please note that \subfloat (as opposite to \subfigure offered by the subfigure package and \subcaptionbox offered by the subcaption package) eats simple spaces (inserted using the space bar key) between them, so you need to place an explicit space here, e.g. \hspace{0.5cm}.
Post Reply