# Display two algorithms side by side

I am using the below code to display several algorithms in a minipage. It works great however they take up a lot of room in my document. Is there are a way to scale and present two algorithms side by side, silimiar to the code at the bottom to display to two images.

\documentclass[11pt]{article}
\usepackage[tmargin=1.25in,bmargin=1.25in,lmargin=1.5in,rmargin=1.5in]{geometry}
\usepackage{times}               % Times Roman
\usepackage[scaled=0.86]{helvet} % Helvetica
\usepackage{sectsty}
\sectionfont{\large\sffamily}
\usepackage{fancyhdr}
\usepackage{mathptmx}            %used to make Title larger

\usepackage[fleqn]{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}

\usepackage[nosectionbib,numberedbib]{apacite}
\AtBeginDocument{\renewcommand\refname{REFERENCES}}

\begin{document}
\raggedright

\pagestyle{fancy}
\rhead{\large\centering{\textit{title at top of all pages}}}
\rfoot{Copyright $\textcopyright$ 2018 me}
\cfoot{}
\sffamily
\noindent\rule{14cm}{1pt}

\begin{center}

\Huge\bfseries\sffamily {\fontsize{35}{60}\selectfont Title}

\vspace{5mm}
\end{center}
\vspace{-\baselineskip}
\noindent\rule{14cm}{1pt}
\fontfamily{ptm}\selectfont

\begin{flushleft}
\vspace{7mm}
\par
\large{\textbf{Author 1, Author 2}}
\vspace{5mm}
\par
\large{\textit{text text text}}
\par

\section*{ABSTRACT}

text text text
\vspace{5mm}
\par
\textit{Keyword:  text, text, text}
\par
\vspace{5mm}
\noindent\rule{14cm}{1pt}
\vspace{5mm}
\par

\section{text}
\label{text2}
\vspace{-3mm}
text text text
\vspace{7mm}
\par

\section*{text}
\label{text2}
\vspace{-3mm}
text text text
\vspace{5mm}
\par

\section*{text}
\vspace{-3mm}
text text text
\vspace{5mm}
\par

\begin{center}
\begin{minipage}{0.7\textwidth}
\begin{algorithm}[H]
\centering
\caption{Example Algorithm}\label{algorithm}
\begin{algorithmic}[1]
\State \text{dataProcessing (dataset)}
\State $\textit{unitToDrop} \gets \text{25\%}$
\State \text{text}
\State \text{text}
\Repeat
\State \text{/*text*/}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{text}$
\State $\text{text}$
\State \text{text}
\State $\text{text}$
\EndFor
\Until {text}
\State \text{text}
\Repeat
\State \text{text}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{v}$
\EndFor
\Until {text}
\State \textbf{Return}  \text{text, text}
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{center}

\vspace{7mm}
\par

\section{text}
\label{text3}
\vspace{-3mm}

\vspace{7mm}
\par

\section{text}
\label{text4}
\vspace{-3mm}

\vspace{7mm}
\par

\section{text}
\label{text5}
\vspace{-3mm}

\vspace{7mm}
\par

\section{text}
\label{text6}
\vspace{-3mm}
text text text
\vspace{7mm}
\par

\bibliographystyle{apacite}
\bibliography{sa.bib}

\section*{text}
\label{text}
\vspace{-7mm}
\par
\noindent\rule{14cm}{1pt}
\vspace{-3mm}
\par
text text text
\vspace{7mm}
\par

\section*{text}
\label{text8}
\vspace{-7mm}
\par
\noindent\rule{14cm}{1pt}
\vspace{-3mm}
\par

\vspace{7mm}
\par

\section*{text}
\label{text9}
\vspace{-7mm}
\par
\noindent\rule{14cm}{1pt}
\vspace{-3mm}
\par
\textbf{text text}  :text text text
\vspace{7mm}
\par

\end{flushleft}
\end{document}


The below code scales and puts two images side by side

\begin{figure}[h!]%
\centering
\subfloat[text]{{\includegraphics[width=6.5cm]{IMG/file.pdf} }}%
\subfloat[text]{{\includegraphics[width=6.5cm]{IMG/file.pdf} }}%
\caption{text}%
\label{twi images}%
\end{figure}

• Can you please make a minimal working example (MWE)? – samcarter is at topanswers.xyz Aug 30 '18 at 18:25
• @samcarter do you mean full code without body of text in sections ? – Bat Aug 30 '18 at 18:28
• Just enough to be able to compile would be enough. The important thing would be to have all the required packages to compile your code snipped. – samcarter is at topanswers.xyz Aug 30 '18 at 18:39
• @samcarter ok ive edited the code in the question. – Bat Aug 30 '18 at 18:54

If you choose a width of <0.5\textwidth for your minipages, you can simply place them side.

If the lines of your algorithms are short enough that is all you need to do. If the lines are too long, you could use a smaller font size, like shown in the second example.

\documentclass[11pt]{article}

\usepackage[fleqn]{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Example Algorithm}\label{algorithm}
\begin{algorithmic}[1]
\State \text{dataProcessing (dataset)}
\State $\textit{unitToDrop} \gets \text{25\%}$
\State \text{text}
\State \text{text}
\Repeat
\State \text{/*text*/}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{text}$
\State $\text{text}$
\State \text{text}
\State $\text{text}$
\EndFor
\Until {text}
\State \text{text}
\Repeat
\State \text{text}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{v}$
\EndFor
\Until {text}
\State \textbf{Return}  \text{text, text}
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Example Algorithm}\label{algorithm1}
\begin{algorithmic}[1]
\State \text{dataProcessing (dataset)}
\State $\textit{unitToDrop} \gets \text{25\%}$
\State \text{text}
\State \text{text}
\Repeat
\State \text{/*text*/}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{text}$
\State $\text{text}$
\State \text{text}
\State $\text{text}$
\EndFor
\Until {text}
\State \text{text}
\Repeat
\State \text{text}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{v}$
\EndFor
\Until {text}
\State \textbf{Return}  \text{text, text}
\end{algorithmic}
\end{algorithm}
\end{minipage}

\end{document}


\documentclass[11pt]{article}

\usepackage[fleqn]{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Example Algorithm}\label{algorithm}
\footnotesize
\begin{algorithmic}[1]
\State \text{dataProcessing (dataset)}
\State $\textit{unitToDrop} \gets \text{25\%}$
\State \text{text}
\State \text{text}
\Repeat
\State \text{/*text*/}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{text}$
\State $\text{text}$
\State \text{text}
\State $\text{text}$
\EndFor
\Until {text}
\State \text{text}
\Repeat
\State \text{text}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{v}$
\EndFor
\Until {text}
\State \textbf{Return}  \text{text, text}
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Example Algorithm}\label{algorithm1}
\footnotesize
\begin{algorithmic}[1]
\State \text{dataProcessing (dataset)}
\State $\textit{unitToDrop} \gets \text{25\%}$
\State \text{text}
\State \text{text}
\Repeat
\State \text{/*text*/}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{text}$
\State $\text{text}$
\State \text{text}
\State $\text{text}$
\EndFor
\Until {text}
\State \text{text}
\Repeat
\State \text{text}
\For{$i\gets 1, rows$}
\State $\text{text}$
\State $\text{v}$
\EndFor
\Until {text}
\State \textbf{Return}  \text{text, text}
\end{algorithmic}
\end{algorithm}
\end{minipage}

\end{document}


• brilliant ! The only problem i have now is some lines are two long and are overlapping. Is it possible to reduce the font size of the text within the algorithms in the minipage ? – Bat Aug 30 '18 at 19:11
• @Bat See my second example. If \footnotesize is still to large, try tiny. – samcarter is at topanswers.xyz Aug 30 '18 at 19:14
• ah brilliant sorry missed that. I wondered why the code was there twice lol. That has now fixed my issue so will accept the answer and upvote. Thanks for help. I have another issue with this template not related to the algorithm so will post that as a seperate question ? – Bat Aug 30 '18 at 19:31
• @Bat Yes, if the new issue is not related to this questions, a new question sounds like a good idea. – samcarter is at topanswers.xyz Aug 30 '18 at 19:35