I would like to save some horizontal space by changing indent space for package algpseudocode
. How can I do that?
I think the variable I have to change is \algorithmicindent
but I can't manage to do that.
\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\section{foo}
Text
\setlength\fboxsep{0pt}
\renewcommand\algorithmicindent{.5em}
\begin{figure}[!ht]
\fbox{
\begin{subfigure}[b]{.5\linewidth}
\centering
\begin{algorithmic}[0]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\caption{Algorithm}\label{fig:alg}
\end{subfigure}%
}
\quad
\begin{subfigure}[b]{.5\linewidth}
\centering
\tikz\draw [fill=red!20] (0,0) rectangle (3,2);
\caption{tikz}\label{fig:tikz}
\end{subfigure}
\caption{Both}\label{fig:both}
\end{figure}
Text \ref{fig:alg} and \ref{fig:tikz} and \ref{fig:both}
\end{document}
* Edit *
And the result of \listfiles
is:
*File List*
article.cls 2007/10/19 v1.4h Standard LaTeX document class
size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
algorithm.sty 2009/08/24 v0.1 Document Style `algorithm' - floating environm
ent
float.sty 2001/11/08 v1.3d Float enhancements (AL)
ifthen.sty 2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
algpseudocode.sty
algorithmicx.sty 2005/04/27 v1.2 Algorithmicx
caption.sty 2010/01/09 v3.1m Customizing captions (AR)
caption3.sty 2010/01/14 v3.1m caption3 kernel (AR)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
subcaption.sty 2008/08/31 v1.0b Adding subcaptions (AR)
tikz.sty 2010/10/13 v2.10 (rcs-revision 1.76)
pgf.sty 2008/01/15 v2.10 (rcs-revision 1.12)
pgfrcs.sty 2010/10/25 v2.10 (rcs-revision 1.24)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v2.10 (rcs-revision 1.7)
graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
trig.sty 1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/message (HO)
ltxcmds.sty 2011/04/18 v1.20 LaTeX kernel commands for general use (HO)
pgfsys.sty 2010/06/30 v2.10 (rcs-revision 1.37)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2008/07/18 (rcs-revision 1.7)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v2.10 (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v2.10 (rcs-revision 1.1)
pgffor.sty 2010/03/23 v2.10 (rcs-revision 1.18)
pgfkeys.sty
pgfkeys.code.tex
pgffor.code.tex
tikz.code.tex
supp-pdf.mkii
pdftexcmds.sty 2011/04/22 v0.16 Utilities of pdfTeX for LuaTeX (HO)
ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO)
ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO)
epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf
grfext.sty 2010/08/19 v1.1 Managing graphics extensions (HO)
kvdefinekeys.sty 2011/04/07 v1.3 Defining keys (HO)
kvoptions.sty 2010/12/23 v3.10 Keyval support for LaTeX options (HO)
kvsetkeys.sty 2011/04/07 v1.13 Key value parser (HO)
etexcmds.sty 2011/02/16 v1.5 Prefix for e-TeX command names (HO)
epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
I'm using a mac. I have installed the latex packages using macports and those are the most recent versions available there.
Best Answer
Your provided example code has some mistakes. The example given in your previous question How to put an algorithm and a tikz drawing (objects of different type) side-by-side in the same float environment? had no mistakes.
I will start with a short analysis of your errors.
First of all it seems that you haven't read any documentation. Sorry for the hard words.
The argument of the environment
subfigure
is the width. You want to have twosubfigure
environments besides each other. A simple calculation shows that.5\linewidth+\quad+.5\linewidth
is greater than\textwidth
. (quad=\hspace{1em}
). The result is an overfull hboxYou set the following combination
and this results in an extra horizontal space because you didn't comment the extra space. The correct form is
You can't encapsule
subfigure
within a\fbox
. Insidesubfigure
you can use the environmentadjustbox
to frame thealgorithmic
environment with the correct width calculation. (Used in the example.)The
algorithmic
environment has no direct solution avoiding the indentation. In the example I redefined the environment itself by adding the length definition:To the
ifequal
test. In this way you can use the optional argument ofalgorithmic
as usual. (Thanks to Werner)A second approach (recommened) is to use the command
patchmd
provided by the packageetoolbox
. (For more information see the documentation). Normally the commandpatchcmd
doesn't work with optional arguments. By a suggest trick (Thanks egreg) we can use the following combination:An explanation is given in the threat How can I use
\patchcmd
with commands with optional arguments?Here is the example: