
전체 코드의 가로 위치를 변경하고 싶습니다. 원한다면 패딩을 제거하세요. 어떻게 해야 합니까?
\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
환경을 설정합니다목록환경이 시작될 때의 구조. 줄 번호 매기기가 있다고 가정하므로 가로 들여쓰기가 남습니다. 줄 번호 매기기를 사용하지 않을 경우에는 make 만 하면 됩니다 \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}%
}%