2

I want to change the horizontal position of the complete code. Remove the padding if you will. How can I do that?

\begin{algorithm}[t!]
\algrenewcommand\algorithmicindent{.1em}%
\caption{With intent no indent}
    \begin{algorithmic}%\
    \Function{\publish[$c, data$]}{}
        \State{algorithmicindent works inside this block only}
    \EndFunction
    \end{algorithmic}%\
\end{algorithm}

enter image description here

1
  • Please show an MWE. I do not know the packages which are needed here. Thanks.
    – LaRiFaRi
    Feb 19, 2016 at 15:34

1 Answer 1

1

algorithmicx sets up the entire algorithmic environment list structure at the start of the environment. It assumes there will be some line numbering and therefore leaves some horizontal indent. If you're never going to use line numbering you can just make \leftmargin, \labelwidth and \labelsep to 0pt using an xpatch of \algorithmic:

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\algorithmic}{\ALG@tlm\z@}{\ALG@tlm\z@\leftmargin 0pt}{}{}
\makeatother

\begin{document}

\begin{algorithm}
  \caption{With intent no indent}
  \begin{algorithmic}
  \Function{Publish[$c$, \textit{data}]}{}
    \State algorithmicindent works inside this block only
  \EndFunction
  \end{algorithmic}
\end{algorithm}

\end{document}

The \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} appends the setting of \leftmargin 0pt immediately after \ALG@tlm\z@. In the construction of the list, this happens just after all the list environment measurements have been set.

Here's a view of the algorithmic environment as defined in algorithmicx.sty, together with the location where the above \xpatchcmd inserts the code:

\newenvironment{algorithmic}[1][0]%
   {%
   \edef\ALG@numberfreq{#1}%
   \def\@currentlabel{\theALG@line}%
   %
   \setcounter{ALG@line}{0}%
   \setcounter{ALG@rem}{0}%
   %
   \let\\\algbreak%
   %
   \expandafter\edef\csname ALG@currentblock@\theALG@nested\endcsname{0}%
   \expandafter\let\csname ALG@currentlifetime@\theALG@nested\endcsname\relax%
   %
   \begin{list}%
      {\ALG@step}%
      {%
      \rightmargin\z@%
      \itemsep\z@ \itemindent\z@ \listparindent2em%
      \partopsep\z@ \parskip\z@ \parsep\z@%
      \labelsep 0.5em \topsep 0.2em%\skip 1.2em 
      \ifthenelse{\equal{#1}{0}}%
         {\labelwidth 0.5em}%
         {\labelwidth 1.2em}%
      \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}% Ok. the perfect leftmargin :-))
      \ALG@tlm\z@% <----- resetting of \leftmargin 0pt inserted here
      }%
   \setcounter{ALG@nested}{0}%
   \ALG@beginalgorithmic%
   }%
   {% end{algorithmic}
   % check if all blocks are closed
   \ALG@closeloops%
   \expandafter\ifnum\csname ALG@currentblock@\theALG@nested\endcsname=0\relax%
   \else%
      \PackageError{algorithmicx}{Some blocks are not closed!!!}{}%
   \fi%
   \ALG@endalgorithmic%
   \end{list}%
   }%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .