# [Tex/LaTex] Adjust width of algorithm float

algorithmsfloatswidth

I am writing a code using the algorithm package. However, I would like to put smaller edges. I used the minipage, boxes and did not work. Could someone give me a suggestion?

I have this

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{algorithm}
%========================
\begin{document}
\section*{Example Algorithm}
%----------------------
\begin{algorithm}
\caption{Penalty function}
\begin{itemize}
\item Let $\{c_k\}$, $k=1,2,\ldots$, 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
\begin{gather*}  minimize \ q(\mu_{k},x), \end{gather*}
obtaining a solution point $x_{k}$.
\end{itemize}
\end{algorithm}
%----------------------
\end{document}


which results

but, I want

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]

We place the non-float algorithm inside a floating figure without using a \caption for the figure.