我正在使用下面的代码在小页面中显示几种算法。效果很好,但它们占用了我文档中的大量空间。有没有办法缩放并并排显示两种算法,类似于底部显示两幅图像的代码。
\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}
下面的代码缩放并并排放置两个图像
\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}
答案1
0.5\textwidth
如果您为小页面选择的宽度为 < ,那么您可以简单地将它们放在一边。
如果您的算法行足够短,那么这就是您需要做的。如果行太长,您可以使用较小的字体大小,如第二个示例所示。
\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}