Adjust width of algorithm float
The algorithm
float is defined using float
's \newfloat
. As a result, the entire float is consumed for possible restructuring (including the placement of the \caption
, which depends on the style). This also affects the possibility of adjusting the width of the float.
One way around this would be to place the float inside a minipage
and make it not float. This is supported by the float
package's [H]
float specification:
\documentclass{article}
\usepackage{amsmath,algorithm}
\begin{document}
\section*{Example Algorithm}
\begin{algorithm}[H]
\caption{Penalty function}
\begin{itemize}
\item Let $\{c_k\}$, $k = 1,2,\dots$, be a sequence tending to infinity such that for each~$k$, $0 \leq c_k < c_{k+1}$.
\item Define the function $$q(\mu_{k},x) = f(x) + \mu_k P(x).$$
\item For each k solve the problem
\[ \text{minimize } q(\mu_k,x),c \]
obtaining a solution point~$x_k$.
\end{itemize}
\end{algorithm}
{\centering
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
\caption{Penalty function}
\begin{itemize}
\item Let $\{c_k\}$, $k = 1,2,\dots$, be a sequence tending to infinity such that for each~$k$, $0 \leq c_k < c_{k+1}$.
\item Define the function $$q(\mu_{k},x) = f(x) + \mu_k P(x).$$
\item For each k solve the problem
\[ \text{minimize } q(\mu_k,x),c \]
obtaining a solution point~$x_k$.
\end{itemize}
\end{algorithm}
\end{minipage}
\par
}
\end{document}
Of course, using a minipage
requires one to use \begin{algorithm}[H]
(to avoid the floating behaviour). If you still want a floating algorithm
, you can use the following work-around:
\begin{figure}[htb]
\centering
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
% <your algorithm>
\end{algorithm}
\end{minipage}
\end{figure}
We place the non-float algorithm
inside a floating figure
without using a \caption
for the figure
.