# Defining a new figure environment

I want to define a new environment, that sets up two \figure side by side. I have already done it manually, but I need to make a shortcut for it, so I can just write "\begin{sidebyside}"+enter to make it appear like normal \figureenvironments do.

This is what i have tried in my Preamble:

\documentclass[a4paper,11pt,fleqn,twoside,openright]{memoir}
\usepackage{caption}
\usepackage{graphicx,caption}
\usepackage{float}

\newenvironment{sidebyside}{
\begin{figure}[H]
\centering
\begin{subfigure}[b]{0.49\textwidth}
\includegraphics[width=\textwidth]{PATH}
\caption{CAPTION}
\end{subfigure}}
%
{\begin{subfigure}[b]{0.49\textwidth}
\includegraphics[width=\textwidth]{PATH}
\caption{CAPTION}
\end{subfigure}
\caption{\protect\raggedright CAPTION FOR THE WHOLE FIGURE}
\label{LABEL}
\end{figure}
}


But it doesn't work. I hope someone can/will help me.

/Lau

You are using memoir which offers special commands for subcaptions. I've declared a newcommand \sidebyside with six parameters, image left, caption for figure on left, image on right, caption for figure on rigth, general caption and general label.

\documentclass[a4paper,11pt,fleqn,twoside,openright]{memoir}
%\usepackage{caption}
\usepackage{graphicx}
%\usepackage{float}

\newsubfloat{figure}

\newcommand{\sidebyside}[6]{
\begin{figure}
\centering
\begin{minipage}[b]{0.49\textwidth}
\includegraphics[width=\textwidth]{#1}
\subcaption{#2}
\end{minipage}
\hfill
\begin{minipage}[b]{0.49\textwidth}
\includegraphics[width=\textwidth]{#3}
\subcaption{#4}
\end{minipage}
\caption{\protect\raggedright #5}
\label{#6}
\end{figure}
}

\begin{document}
\sidebyside{example-image-a}{test a}{example-image-b}{test b}{general caption}{mylabel}
\end{document}


• If anyone else needs this with book class (which I need), add \usepackage{subcaption} to the preamble. – Jon Oct 31 '18 at 14:47