# Minipage like Environment in latex capturing side by side float

Need a single command to capture the multiple floats. The PDF output of the floats should be set in side by side. i have tried the below macro. i'm getting

! LaTeX Error: Not in outer par mode


is there any way to produce the single command with multiple floats?

\documentclass{book}

\def\sidebysidefig#1#2{\begin{minipage}{0.45\textwidth}{#1}{#2}\end{minipage}}

\begin{document}

\chapter{Mathematical Expression $\sin\theta\,\cos\theta$}

\sidebysidefig{\begin{figure}
%\includegraphics{fig1.eps}
\caption{This is sample caption}\end{figure}}{\begin{figure}
%\includegraphics{fig2.eps}
\caption{This is sample caption}\end{figure}}

\end{document}

• you had not to close floats into minipage. you should do opposite: in figure put your \sidebysidefig: \begin{figure}\sidebysidefig{ ..}{....}\end{figure}. – Zarko May 6 at 6:57
• i do understand but, for generating the XML will be tedious task. that is the reason where I was looking for single command. – Saravanan.O May 6 at 7:29
• why is it any more tedious than your suggested markup? you only need a single figure around the outside, the content of the figure is side by side or vertical just depending if you put the items in the same paragraph or separate paragraphs. – David Carlisle May 6 at 9:49
• We have automated the figure calling methods. We are not using the \begin{figure}...\end{figures} instead, we will be using \processfigure{Position}{caption}{figure}. based on the figure width conditions, we have automated the landscape and side caption figures. if i changed the coding structure the entire process need to be updated. That is the reason where i have requested for single command with multiple floats. Hope you understand my requirements. – Saravanan.O May 6 at 10:42
• structurally there is no difference, you want a single thing around the set of side by side floats you suggest \sidebysidefig but I suggest figure then you have an environment around each float you suggest figure but I use minipage so the structure is as you want, just using different names. – David Carlisle May 6 at 11:08

figure environments need to be at the top level so they can float, but you do not need anything special to put content side-by-side:

\documentclass{book}

\usepackage{graphicx}
\begin{document}

\chapter{Mathematical Expression $\sin\theta\,\cos\theta$}

\begin{figure}
\begin{minipage}{.45\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{This is sample caption}
\end{minipage}\hfill
\begin{minipage}{.45\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{This is sample caption}
\end{minipage}
\end{figure}

\end{document}

• Thanks for the update. unfortunately this could not be suit for my requirements. We have more combination of floats will be available. Figure and table, figure and listing, listing and table etc. without changing the coding need to be produce the side by side floats. that is the reason where i have requested for the single command. – Saravanan.O May 6 at 10:49
• @Saravanan.O you may need to relax your requirements. All the items that are side by side need to float together so need to be in a figure or table environment as shown, you can have a table in a figure environment by using the capt-of package and using \captionof{table}{my caption} instead of \caption{my caption} although ordering with other tables is then not guaranteed – David Carlisle May 6 at 10:55