Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Looking for a way to set the width of an algorithm environment, preferably document wide (as opposed to per-algorithm). Thought it should be fairly easy, but couldn't find a particularly good solution.

Found this one here (wrap an algorithm in a minipage in a float, which is relatively okay, but surely there's a simpler way)?

\documentclass{article}
\usepackage{algorithm}
\floatstyle{plain}
\newfloat{myalgo}{tbhp}{mya}

\newenvironment{Algorithm}[2][tbh]%
{\begin{myalgo}[#1]
\centering
\begin{minipage}{#2}
\begin{algorithm}[H]}%
{\end{algorithm}
\end{minipage}
\end{myalgo}}

\begin{document}
\begin{Algorithm}[t]{10cm}
\caption{Does work, though no nice solution.}
\end{Algorithm}
\end{document}
share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

\floatevery{algorithm}{\setlength\hsize{10cm}} would limit the algorithm environment to a width of 10cm, but would not center it. (For additional centering one needs to re-define internal macros of the float package which does not sound like an elegant solution to me.)

So I'm afraid, the solution you have found seems to be quite good and if you would like to have the width setting global you could simply change the definition of Algorithm, e.g.:


\documentclass{article}
\usepackage{algorithm}
\floatstyle{plain}
\newfloat{myalgo}{tbhp}{mya}

\newenvironment{Algorithm}[1][tbh]%
{\begin{myalgo}[#1]
\centering
\begin{minipage}{10cm}
\begin{algorithm}[H]}%
{\end{algorithm}
\end{minipage}
\end{myalgo}}

\begin{document}
\begin{Algorithm}[t]
\caption{Does work, though no nice solution.}
\end{Algorithm}
\end{document}
share|improve this answer
    
Thanks! (Just wanted to make sure I wasn't missing something.) –  badroit Dec 21 '10 at 17:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.