[Tex/LaTex] Display two algorithms side by side

algorithms

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}
\renewcommand{\headrulewidth}{0pt}
\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} }}%
    \qquad
    \subfloat[text]{{\includegraphics[width=6.5cm]{IMG/file.pdf} }}%
    \caption{text}%
    \label{twi images}%
\end{figure}

Best Answer

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}

enter image description here

\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}

enter image description here

Related Question