отступ алгоритмический снаружи блока

отступ алгоритмический снаружи блока

Я хочу изменить горизонтальное положение всего кода. Уберите отступ, если хотите. Как это сделать?

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

введите описание изображения здесь

решение1

algorithmicxнастраивает всю algorithmicсредусписокструктура в начале среды. Она предполагает, что будет некоторая нумерация строк и поэтому оставляет некоторый горизонтальный отступ. Если вы никогда не собираетесь использовать нумерацию строк, вы можете просто сделать \leftmargin, \labelwidthи \labelsepиспользовать0ptxpatchиз \algorithmic:

введите описание изображения здесь

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

Добавляет \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}настройку \leftmargin 0ptсразу после \ALG@tlm\z@. При построении списка это происходит сразу после того, как были установлены все измерения среды списка.

Вот взгляд на algorithmicокружающую среду, как она определена вalgorithmicx.sty, вместе с местом, куда выше \xpatchcmdвставляется код:

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

Связанный контент