Graphics, Figures & Tablesautomatic subfig figure arrangement (like subfigure)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

automatic subfig figure arrangement (like subfigure)

Post by crobar »

Hello,

I am writing a scientific paper which I would like to view in both single column and double column format. I have a number of figures in the paper, some of which I wish to arrange as subfigures.

I had been using the old subfigure package to achieve this which was working fine, but had come to a set of two figures which I wished to display side by side, vertically aligned at their centres. Therefore I am attempting to instead use the newer subfig package, which has examples of this type.

When using the original subfigure package, I found that my subfigures would nicely rearrange themselves when switching between twocolumn and onecolumn mode. By this I mean, the subfigures lined up side by side in single column mode, but rearranged themselves to be on top of one another when using two columns, presumeably recognising there was insufficient space to have them beside one another.

I have found that the subfig package does not automatically have the same functionality and I must manually choose the orientation of my floats, otherwize, they overlay with the text of the right hand column.

Is there any way to achieve the same results with subfig as with subfigure in this respect?

I am declaring subfig with the caption = false and font=footnotesize as below, and most of my figures have been created using tikz pgf in case this has any bearing.

Code: Select all

\usepackage[caption=false,font=footnotesize]{subfig}
Thanks,
Richard

Recommended reading 2024:

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

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

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

automatic subfig figure arrangement (like subfigure)

Post by sommerfee »

Unfortunately you did not read the forum rules and therefore haven't provided a minimal but complete example. So I can only guess:

The subfig package is removing space between the \subfloat commands, which is something the subfigure package is not doing. So if you write

Code: Select all

\subfigure{...}
\subfigure{...}
a space will be entered between those two subfigures. Because of this space a linebreak can happen, maybe this is what you mean by "rearranging"!?
When using the subfig package this space will be removed, therefore

Code: Select all

\subfloat{...}
\subfloat{...}
will always put both figures side-by-side.
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

automatic subfig figure arrangement (like subfigure)

Post by crobar »

Hello,

thanks for replying. Sorry for not supplying a minimal example, in this case I thought my problem was rather generic, so either someone would know the answer immediately or they would not.

Below is an example with lorem ipsum to demostrate what I mean

Code: Select all

\documentclass[twocolumn]{report}

\usepackage{subfig}
\usepackage{subfigure}
\usepackage{tikz}


\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In faucibus aliquam fringilla. Proin et dui vitae erat scelerisque tempor. Donec ullamcorper sagittis lorem nec ultricies. Maecenas elementum tincidunt nisl, ornare blandit massa facilisis ut. Duis ac erat et odio faucibus hendrerit. Maecenas pharetra arcu eget tortor rhoncus feugiat. Proin nibh lectus, feugiat eu eleifend vel, congue id lectus. Maecenas viverra condimentum suscipit. Vestibulum sit amet orci eu risus eleifend bibendum. Aliquam erat volutpat. Sed sodales diam at dolor commodo hendrerit sed id nibh. Duis semper nisi et est ultricies sit amet aliquam dui sodales. Pellentesque at fermentum massa.

\begin{figure}
	\subfloat[a float]{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}	
	}
	\subfloat[another float]
	{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}		
	}
\end{figure}
Nunc a urna id est eleifend ullamcorper. Sed erat felis, viverra eu blandit a, tempor nec ante. Etiam porta nulla nisi, at gravida lorem. Suspendisse at lorem interdum augue suscipit interdum. Nam gravida tellus nec velit iaculis ac ultricies dolor luctus. Morbi imperdiet varius lacus ac fermentum. Etiam auctor gravida sem facilisis gravida. Sed eget viverra lorem. Nulla mi felis, dapibus eget malesuada non, imperdiet vel est. Nam id sem et lorem iaculis elementum ut sit amet magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed posuere blandit ligula nec imperdiet. Morbi vitae lectus at leo varius venenatis sed vel mi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi sodales accumsan accumsan.

Donec sodales diam sit amet neque gravida rhoncus. Sed quis nunc dolor, id luctus nulla. Curabitur vitae mi ante. Duis arcu orci, pulvinar sed ultrices eget, ultricies sed mauris. Suspendisse facilisis molestie ante et convallis. Pellentesque dictum augue sed lacus suscipit congue. Sed sit amet dolor at dolor porta ultrices ac in nibh. Morbi elit orci, venenatis cursus posuere at, hendrerit sed ipsum. Aliquam a ligula vel ligula pharetra iaculis. Donec non convallis eros. Duis ac elit lacus.

Proin arcu quam, vehicula a consequat adipiscing, vestibulum et purus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus posuere sollicitudin dapibus. Vestibulum non purus orci, eget fermentum dolor. Vivamus at varius orci. Aliquam dapibus semper rhoncus. Nulla sagittis malesuada odio, ut lacinia ante rhoncus aliquet. Nulla posuere leo non augue commodo facilisis auctor quam rhoncus. Ut hendrerit, augue at imperdiet volutpat, est urna congue velit, nec varius ligula nunc sit amet orci. Suspendisse ac dui tortor. Aliquam congue metus nec turpis condimentum accumsan. Maecenas tristique, sapien vitae mattis convallis, augue mi ullamcorper augue, non vulputate odio leo vel magna. Vivamus vel lorem sapien, id tristique ligula. Nam porttitor nunc quis mauris tincidunt dignissim. Praesent diam elit, sagittis eget gravida nec, tristique a odio. Ut in arcu vitae nisi luctus varius. Nullam elit felis, accumsan eu consequat at, porta ultricies mi. 

Nunc a urna id est eleifend ullamcorper. Sed erat felis, viverra eu blandit a, tempor nec ante. Etiam porta nulla nisi, at gravida lorem. Suspendisse at lorem interdum augue suscipit interdum. Nam gravida tellus nec velit iaculis ac ultricies dolor luctus. Morbi imperdiet varius lacus ac fermentum. Etiam auctor gravida sem facilisis gravida. Sed eget viverra lorem. Nulla mi felis, dapibus eget malesuada non, imperdiet vel est. Nam id sem et lorem iaculis elementum ut sit amet magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed posuere blandit ligula nec imperdiet. Morbi vitae lectus at leo varius venenatis sed vel mi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi sodales accumsan accumsan.

Donec sodales diam sit amet neque gravida rhoncus. Sed quis nunc dolor, id luctus nulla. Curabitur vitae mi ante. Duis arcu orci, pulvinar sed ultrices eget, ultricies sed mauris. Suspendisse facilisis molestie ante et convallis. Pellentesque dictum augue sed lacus suscipit congue. Sed sit amet dolor at dolor porta ultrices ac in nibh. Morbi elit orci, venenatis cursus posuere at, hendrerit sed ipsum. Aliquam a ligula vel ligula pharetra iaculis. Donec non convallis eros. Duis ac elit lacus.

Proin arcu quam, vehicula a consequat adipiscing, vestibulum et purus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus posuere sollicitudin dapibus. Vestibulum non purus orci, eget fermentum dolor. Vivamus at varius orci. Aliquam dapibus semper rhoncus. Nulla sagittis malesuada odio, ut lacinia ante rhoncus aliquet. Nulla posuere leo non augue commodo facilisis auctor quam rhoncus. Ut hendrerit, augue at imperdiet volutpat, est urna congue velit, nec varius ligula nunc sit amet orci. Suspendisse ac dui tortor. Aliquam congue metus nec turpis condimentum accumsan. Maecenas tristique, sapien vitae mattis convallis, augue mi ullamcorper augue, non vulputate odio leo vel magna. Vivamus vel lorem sapien, id tristique ligula. Nam porttitor nunc quis mauris tincidunt dignissim. Praesent diam elit, sagittis eget gravida nec, tristique a odio. Ut in arcu vitae nisi luctus varius. Nullam elit felis, accumsan eu consequat at, porta ultricies mi.
\begin{figure}
	\subfigure[a float]{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}	
	}
	\subfigure[another float]
	{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}		
	}
\end{figure}

\end{document}


Note the 'rearrangement of the subfigures so one is vertically above the other, whereas the subfloats just spread into the column beside.

p.s. this code will generate errors as subfig attempts to redefine the \subfigure command, but on my system it still compiles and shows the problem.
Thanks,

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

automatic subfig figure arrangement (like subfigure)

Post by sommerfee »

crobar wrote: Note the 'rearrangement of the subfigures so one is vertically above the other, whereas the subfloats just spread into the column beside.
It seems that I have guessed right - the reason for this is described in my posting above. So if you want to allow line breaks between \subfloats you have to put something between the \subfloats where LaTeX can make a line break. A simple space (or newline) was sufficient for \subfigure, but is not sufficient for \subfloat anymore.
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

automatic subfig figure arrangement (like subfigure)

Post by crobar »

Thanks, you're right, adding an \hspace{0}, as in the following code gave me the same results!

Code: Select all

\begin{figure}
	\subfloat[a float]{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}	
	}
	\hspace{0}
	\subfloat[another float]
	{
		\begin{tikzpicture}
			\draw (0,0) rectangle (6,6);
		\end{tikzpicture}		
	}
\end{figure}
Thanks,
Richard
Post Reply