
コード全体の水平位置を変更したいです。パディングを削除してください。どうしたらいいでしょうか?
\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
て0pt
、xpatch
の\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}%
}%