recuar algorítmico fora de um bloco

recuar algorítmico fora de um bloco

Quero alterar a posição horizontal do código completo. Remova o preenchimento, se desejar. Como eu posso fazer isso?

\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}

insira a descrição da imagem aqui

Responder1

algorithmicxconfigura todo o algorithmicambientelistaestrutura no início do ambiente. Ele assume que haverá alguma numeração de linha e, portanto, deixa algum recuo horizontal. Se você nunca vai usar numeração de linha você pode simplesmente fazer \leftmargin, \labelwidthe \labelsepusar 0ptumxpatchde \algorithmic:

insira a descrição da imagem aqui

\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}

O \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}anexa a configuração \leftmargin 0ptimediatamente após \ALG@tlm\z@. Na construção da lista, isso acontece logo após todas as medidas do ambiente da lista terem sido definidas.

Aqui está uma visão do algorithmicambiente conforme definido emalgorithmicx.sty, junto com o local onde o acima \xpatchcmdinsere o código:

\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}%
   }%

informação relacionada