7

I'm familiar with using minipages inside a float to effectively place two floats side-by-side, but is there a way to do this with different float types? Eg a Figure and a Scheme (chemscheme)?

lockstep
  • 250,273
JMS
  • 71
  • 1
    See http://tex.stackexchange.com/questions/6850/table-and-figure-side-by-side-with-independent-captions. – lockstep Oct 22 '11 at 09:35
  • Welcome to TeX.sx! This question is very similar to the one lockstep pointed you to. Please take a look at it as the information there might help you. If so, that's great, and we'll probably close this question as a duplicate just to keep the place tidy and to help people find answers quickly. If not, please edit your question here to explain why so that people can better focus their attention to help you. – doncherry Oct 22 '11 at 12:41

2 Answers2

7
\documentclass{article}  
\usepackage[demo]{graphicx}% delete demo later
\usepackage{chemscheme}
\usepackage{caption}
\begin{document}

\begin{scheme}
 \begin{floatrow}
  \ffigbox[\FBwidth]
    {\includegraphics[width=0.45\textwidth]{normalimage}}
    {\caption{My figure}\label{foo}}
  \ffigbox[\FBwidth]
    {\includegraphics[width=0.45\textwidth]{chemfig}}%
    {\captionof{scheme}{My chem scheme}\label{bar}}
 \end{floatrow}
\end{scheme}

\end{document}

enter image description here

4

Simply use one float environment with two minipages inside. Then use the normal \caption for the one float and \captionof{<other type>}{<caption text>} for the other. This needs either the caption or the capt-of package.


The issue with scheme from chemscheme is that it isn't a normal float but (by default) defined using floatrow which doesn't support code like above (I get a 'caption lost' error). The alternate definition over the float package doesn't work either because it always places the caption on its own and not part of the actual content, so it breaks out of the minipage.

I now found the following solution which undoes some stuff from the floatrow package and define scheme the same way as figure:

\documentclass{article}

\usepackage[demo]{graphicx}% 'demo' option only to not require actually images for this example file
\usepackage{capt-of}% or 'caption'
\usepackage{chemscheme}

\begin{document}
\makeatletter
\def\scheme{\@float{scheme}}
\let\endscheme\endfigure
\makeatother

\begin{scheme}
    \begin{minipage}{.48\textwidth}
        \includegraphics[width=\textwidth]{normalimage}
        \captionof{figure}{My figure}
    \end{minipage}%
    \hfill
    \begin{minipage}{.48\textwidth}
        \includegraphics[width=\textwidth]{chemfig}
        \caption{My chem scheme}
    \end{minipage}%
\end{scheme}

\end{document}

However, putting \captionof{scheme} into a figure environment still doesn't work ('caption lost' error again).

You would recommend to wait until someone which knows floatrow better than me posts an answer.

Martin Scharrer
  • 262,582
  • 1
    I downvoted this because the usage of \RawFloats inside this scheme environment would be a much cleaner (and documented) solution. I'm always angry about such patches since after using three to six such "solutions" the user gets into trouble and is asking package authors (like me) for help via e-mail afterwards. –  Oct 22 '11 at 10:18
  • @AxelSommerfeldt: No problem. It is a hack after all. Can you tell me why scheme and other floats are not defined exactly the same way than figure and table? It is a shame that e.g. float doesn't allow for arbitrary content. – Martin Scharrer Oct 22 '11 at 11:19
  • Yes, it's a shame. AFAIK scheme is simply not defined like figure and table because it uses the floatrow package for defining it. The floatrow package does not do it this way because it was designed as an extension to the float package first. And the float package follows the idea of having "float styles" but forget to offer a macro to define new non-styled floating environments. –  Oct 22 '11 at 12:07
  • 1
    KOMA-Script and the caption package are offering macros for defining new floating environments which behave like figure and table, but IMHO it would be overkill to include them for just defining new floating environments. Maybe I should split that functionality into a new package called newfloat or similar? –  Oct 22 '11 at 12:11
  • @AxelSommerfeldt: I had the same idea about a newfloat package. However, a CTAN search gave me Joseph Wright's trivfloat package which seems to do this. – Martin Scharrer Oct 22 '11 at 12:13
  • No, trivfloat is just using the float package, offering an easier syntax for beginners. –  Oct 22 '11 at 12:20
  • @AxelSommerfeldt: Ah, thanks! I misread the abstract of the package. – Martin Scharrer Oct 22 '11 at 12:24
  • I'm just extracting \DeclareFloatingEnvironment from my caption3 package to a newfloat package... –  Oct 22 '11 at 13:42
  • @AxelSommerfeldt: Ah, I just did the same with the LaTeX core code: https://bitbucket.org/martin_scharrer/newfloat :-) But I don't have an issue with not using it. Your existing code should be much better tested. – Martin Scharrer Oct 22 '11 at 16:12
  • Are you sure you really want to do this? ;-) Such package needs to be adapted to various document classes and packages, e.g. for having a skip between list entries on \chapter boundaries. And I'm used to such package hell. No, I'm not saying that I'm tougher than you (in fact I'm quite a wimp), but I already have all code for this (except for memoir, but I'm just adapting it with help of Lars Madsen), and if I had known all this is the past, I would have never released a caption package at all. –  Oct 22 '11 at 17:49