General ⇒ Strip of subfigures: difficult to have?
Strip of subfigures: difficult to have?
Hello,
I frequently have to introduce several subfigures in my articles. Usually a figure is in form of a single horizontal "strip" of images, each with the same height.
Since each image has a different width/height ratio, it's not easy to know the correct width for each image so that their height is the same.
So what I'm after is an easy way to insert some images in a strip: ideally, I should not need to specify any size, and the software automatically choosing a correct scale for each of the images so that they all have the same height and the total width is \textwidth, also accounting a given (possibly fixed) spacing between the images.
AFAIK the subfigure package does not have this functionality
I frequently have to introduce several subfigures in my articles. Usually a figure is in form of a single horizontal "strip" of images, each with the same height.
Since each image has a different width/height ratio, it's not easy to know the correct width for each image so that their height is the same.
So what I'm after is an easy way to insert some images in a strip: ideally, I should not need to specify any size, and the software automatically choosing a correct scale for each of the images so that they all have the same height and the total width is \textwidth, also accounting a given (possibly fixed) spacing between the images.
AFAIK the subfigure package does not have this functionality
NEW: TikZ book now 40% off at Amazon.com for a short time.
Strip of subfigures: difficult to have?
If you're willing to manually adjust the height, you can use the "height" option of graphicx's includegraphics to do what you need. Consider something like...lalelale wrote:So what I'm after is an easy way to insert some images in a strip: ideally, I should not need to specify any size, and the software automatically choosing a correct scale for each of the images so that they all have the same height and the total width is \textwidth, also accounting a given (possibly fixed) spacing between the images.
AFAIK the subfigure package does not have this functionality
Code: Select all
% In preamble (at least the \newlength line)
\newlength{\subfigheight}
\setlength{\subfigheight}{1in}
Code: Select all
% In main document
\begin{figure}\centering
\subfloat{ \includegraphics[height=\subfigheight]{image1} }
\subfloat{ \includegraphics[height=\subfigheight]{image2} }
\subfloat{ \includegraphics[height=\subfigheight]{image3} }
\subfloat{ \includegraphics[height=\subfigheight]{image4} }
\subfloat{ \includegraphics[height=\subfigheight]{image5} }
\end{figure}
Note that \setlength can be called within the document. If you call it outside of a group, it will change the value permanently from that point on. However, if you change it within a group (like a figure), then it will only change inside that group. So I imagine seeing lots of ...
Code: Select all
\begin{figure}\centering
\setlength{\subfigheight}{1.5in}
\subfloat{ \includegraphics[height=\subfigheight]{image1} }
\subfloat{ \includegraphics[height=\subfigheight]{image2} }
\subfloat{ \includegraphics[height=\subfigheight]{image3} }
\subfloat{ \includegraphics[height=\subfigheight]{image4} }
\subfloat{ \includegraphics[height=\subfigheight]{image5} }
\end{figure}
Code: Select all
\begin{figure}\centering
\setlength{\subfigheight}{1.5in}
\subfloat{ \includegraphics[height=\subfigheight]{image1} }
\subfloat{ \includegraphics[height=\subfigheight]{image2} }
\subfloat{ \includegraphics[height=\subfigheight]{image3} }
\subfloat{ \includegraphics[height=\subfigheight]{image4} }
\subfloat{ \includegraphics[height=\subfigheight]{image5} }\\
\setlength{\subfigheight}{2.5in}
\subfloat{ \includegraphics[height=\subfigheight]{image6} }
\subfloat{ \includegraphics[height=\subfigheight]{image7} }
\subfloat{ \includegraphics[height=\subfigheight]{image8} }
\end{figure}
Code: Select all
% Centered and flushed left and right
\begin{figure}
\subfloat{ \includegraphics[height=\subfigheight]{image1} }
\hfill
\subfloat{ \includegraphics[height=\subfigheight]{image2} }
\hfill
\subfloat{ \includegraphics[height=\subfigheight]{image3} }
\hfill
\subfloat{ \includegraphics[height=\subfigheight]{image4} }
\hfill
\subfloat{ \includegraphics[height=\subfigheight]{image5} }
\end{figure}
Code: Select all
% Centered with equal space between and beside
\begin{figure}
\centerline{%
\subfloat{ \includegraphics[height=\subfigheight]{image1} }
\hss
\subfloat{ \includegraphics[height=\subfigheight]{image2} }
\hss
\subfloat{ \includegraphics[height=\subfigheight]{image3} }
\hss
\subfloat{ \includegraphics[height=\subfigheight]{image4} }
\hss
\subfloat{ \includegraphics[height=\subfigheight]{image5} }
}
\end{figure}
Strip of subfigures: difficult to have?
Yeah, very useful. In combination to kile's preview feature, it may help a lot.Ted wrote: Does that help?
Still, it would be very useful to have a package to compute that height automatically, but I guess it's not there yet

Thank you!

Only one question: is there any difference in using subfloat or subfigure there?
Re: Strip of subfigures: difficult to have?
Yeah I confirm, it works great with Kile's quickpreview. 2-3 iterations often suffice to find a good-looking value.
Just a comment: what about defining the \subfigheight as a fraction of \textwidth? This should ensure that if \textwidth is changed, the layout of the subfigures is not mangled. True?
Just a comment: what about defining the \subfigheight as a fraction of \textwidth? This should ensure that if \textwidth is changed, the layout of the subfigures is not mangled. True?
Strip of subfigures: difficult to have?
Such a package would have to jam everything on the line stretched to a common height, allowing for an overfull hbox, and measure the box_width/columnwidth ratio. It would then scale the height by the ratio. Such a package would have to merge features of subfloat and graphicx, which are two very unrelated packages. So I'm guessing that such a package won't exist in the near future.lalelale wrote:Still, it would be very useful to have a package to compute that height automatically, but I guess it's not there yet

However, you could do something similar yourself. If I had this problem, I'd make my fixed height very small and use my previewer (Skim on a Mac) to measure the resulting width. I'd then do the scaling based on my measurement. So in two tries, I'd have the right width.
You are probably using the old subfigure package. Instead, you should be using the subfig package, which supersedes subfigure. The subfig package uses "subfloats" rather than "subfigs." They're nearly identical, except the language makes more sense. That is, you should be able to have "subtables". Saying "subfloat" is more general.lalelale wrote:Only one question: is there any difference in using subfloat or subfigure there?
Similarly, the memoir document class has \subbottom (and \subtop, I think) that works just like subfloat (and subfigure). Additionally, you can use subfig (or subfigure, but you should use subfig) to get features of subfig within memoir.
Strip of subfigures: difficult to have?
That's totally fine. I was just keeping things simple to make all of the mechanisms clear.lalelale wrote:Just a comment: what about defining the \subfigheight as a fraction of \textwidth? This should ensure that if \textwidth is changed, the layout of the subfigures is not mangled. True?
Personally, I often resize with respect to \columnwidth. Of course, it is going to depend on what you're resizing and where it is.
Re: Strip of subfigures: difficult to have?
Thanks again,
you have been incredibly helpful and instructive
you have been incredibly helpful and instructive

Re: Strip of subfigures: difficult to have?
This is a very useful feature, and one I wanted very recently. In the end I solved it in the by varying the height until it looked good.
Perhaps one day this thread will be updated with a package which solves this
Perhaps one day this thread will be updated with a package which solves this

-
- Posts: 1
- Joined: Tue Jun 03, 2014 5:07 pm
Re: Strip of subfigures: difficult to have?
hey,
if i understand the original question right, the solution is given here by herbert:
http://tex.stackexchange.com/questions/ ... ame-height
that is only for two figures next to each other; i have added two things in order to have subfloats instead (\subfloat[]{...} and \setcounter{subfigure}).
cheers, maybe this helps someone
\begin{figure}
\setbox0\hbox{%
\subfloat[]{\includegraphics[width=.45\textwidth]{fig1.png}}%
}%
\setbox2\hbox{%
\subfloat[]{\includegraphics[width=.45\textwidth]{fig2.png}}%
}%
\ifdim\ht0>\ht2
\setbox0\hbox{%
\setcounter{subfigure}{0}
\subfloat[]{\includegraphics[height=\ht2]{fig1.png}}%
}%
\else
\setbox2\hbox{%
\setcounter{subfigure}{1}
\subfloat[]{\includegraphics[height=\ht0]{fig2.png}}%
}%
\fi
\noindent
\parbox{.45\textwidth}{%
\centering
\unhbox0
% \caption{This is figure 1.}
\label{fig:fig1}
}%
\hfil
\parbox{.45\textwidth}{%
\centering
\unhbox2
% \caption{This is figure 2.}
\label{fig:fig2}
}%
\caption{Two nice figures.}
\end{figure}
if i understand the original question right, the solution is given here by herbert:
http://tex.stackexchange.com/questions/ ... ame-height
that is only for two figures next to each other; i have added two things in order to have subfloats instead (\subfloat[]{...} and \setcounter{subfigure}).
cheers, maybe this helps someone

\begin{figure}
\setbox0\hbox{%
\subfloat[]{\includegraphics[width=.45\textwidth]{fig1.png}}%
}%
\setbox2\hbox{%
\subfloat[]{\includegraphics[width=.45\textwidth]{fig2.png}}%
}%
\ifdim\ht0>\ht2
\setbox0\hbox{%
\setcounter{subfigure}{0}
\subfloat[]{\includegraphics[height=\ht2]{fig1.png}}%
}%
\else
\setbox2\hbox{%
\setcounter{subfigure}{1}
\subfloat[]{\includegraphics[height=\ht0]{fig2.png}}%
}%
\fi
\noindent
\parbox{.45\textwidth}{%
\centering
\unhbox0
% \caption{This is figure 1.}
\label{fig:fig1}
}%
\hfil
\parbox{.45\textwidth}{%
\centering
\unhbox2
% \caption{This is figure 2.}
\label{fig:fig2}
}%
\caption{Two nice figures.}
\end{figure}
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Strip of subfigures: difficult to have?
Thnaks for sharing.
Can you edit your post and make it compilable (MWE, Herbert did the same)? Please also use the code button, this way one can easily test the code unsing the link above the code (»Open in Writelatex«). You also might find the example pictures of package mwe helpful.
Can you edit your post and make it compilable (MWE, Herbert did the same)? Please also use the code button, this way one can easily test the code unsing the link above the code (»Open in Writelatex«). You also might find the example pictures of package mwe helpful.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.