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

\caption{With intent no indent}
    \Function{\publish[$c, data$]}{}
        \State{algorithmicindent works inside this block only}

enter image description here

  • 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


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



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


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


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:

   \expandafter\edef\csname ALG@currentblock@\theALG@nested\endcsname{0}%
   \expandafter\let\csname ALG@currentlifetime@\theALG@nested\endcsname\relax%
      \itemsep\z@ \itemindent\z@ \listparindent2em%
      \partopsep\z@ \parskip\z@ \parsep\z@%
      \labelsep 0.5em \topsep 0.2em%\skip 1.2em 
         {\labelwidth 0.5em}%
         {\labelwidth 1.2em}%
      \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}% Ok. the perfect leftmargin :-))
      \ALG@tlm\z@% <----- resetting of \leftmargin 0pt inserted here
   {% end{algorithmic}
   % check if all blocks are closed
   \expandafter\ifnum\csname ALG@currentblock@\theALG@nested\endcsname=0\relax%
      \PackageError{algorithmicx}{Some blocks are not closed!!!}{}%

You must log in to answer this question.

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