sangría algorítmica fuera de un bloque

sangría algorítmica fuera de un bloque

Quiero cambiar la posición horizontal del código completo. Retire el acolchado si lo desea. ¿Cómo puedo hacer eso?

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

ingrese la descripción de la imagen aquí

Respuesta1

algorithmicxconfigura todo el algorithmicentornolistaestructura al inicio del entorno. Se supone que habrá alguna numeración de líneas y, por lo tanto, deja cierta sangría horizontal. Si nunca vas a utilizar la numeración de líneas, puedes simplemente crear \leftmarginy usar un\labelwidth\labelsep0ptxpatchde \algorithmic:

ingrese la descripción de la imagen aquí

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

Agrega \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}la configuración de \leftmargin 0ptinmediatamente después \ALG@tlm\z@. En la construcción de la lista, esto sucede justo después de que se hayan establecido todas las medidas del entorno de la lista.

A continuación se muestra una vista del algorithmicentorno tal como se define enalgorithmicx.sty, junto con la ubicación donde lo anterior \xpatchcmdinserta el 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}%
   }%

información relacionada