
Ich verwende das algorithmic
Paket, um Code anzuzeigen. Um rechtsbündige, linksbündige Kommentare zu erhalten, verwende ich auch das eqparbox
Paket und definiere es neu \algorithmiccomment
; siehe Minimalbeispiel unten.
Wie im beigefügten Schnappschuss zu sehen ist, sind alle Kommentare bis auf den zweiten wie vorgesehen linksbündig ausgerichtet. Ich vermute, dass sich das Problem lösen lässt, indem man einen Befehl in neu definiert oder patcht algorithmic.sty
, aber nachdem ich einen Blick in die Datei geworfen habe, konnte ich die Ursache des Problems nicht identifizieren. Irgendwelche Ideen?
\documentclass{article}
\usepackage{algorithmic}
\usepackage{eqparbox}
\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\{#1\}}}
\begin{document}
\begin{algorithmic}
\STATE something \COMMENT{first comment}
\IF[second comment]{some condition}
\STATE some other thing \COMMENT{3rd comm}
\STATE final thing \COMMENT{some final thoughts}
\ENDIF
\end{algorithmic}
\end{document}
Antwort1
Dieses Problem ist bereits bekannt, sieheFehlerhafte Rechtsausrichtung für Kommentare im algorithmischen Paket.
algorithmicx
Der richtige Weg ist, (insbesondere algpseudocode
Variante) anstelle von zu verwenden algorithmic
. Sie können die Option verwenden, compatible
wenn Sie Ihren Code genau so behalten möchten, wie er ist.
MWE:
\documentclass{article}
\usepackage[compatible]{algpseudocode} % or \usepackage{algcompatible}
\usepackage{eqparbox}
\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\{#1\}}}
\begin{document}
\begin{algorithmic}
\STATE something \COMMENT{first comment}
\IF[second comment]{some condition}
\STATE some other thing \COMMENT{3rd comm}
\STATE final thing \COMMENT{some final thoughts}
\ENDIF
\end{algorithmic}
\end{document}
Ausgabe:
Antwort2
Hier ist eine korrigierte Version von algorithmic.sty
, speichern Sie sie alsfixed-algorithm.sty
%%%%%%%%%%%% modified to protect end-of-lines
%%% see http://tex.stackexchange.com/questions/229559/spacing-issue-with-algorithmic-and-eqparbox
%%
%% This is file `algorithmic.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% algorithms.dtx (with options: `algorithmic')
%% This is a generated file.
%%
%% Copyright (C) 1994-2004 Peter Williams <[email protected]>
%% Copyright (C) 2005-2009 Rogério Brito <[email protected]>
%%
%% This document file is free software; you can redistribute it and/or
%% modify it under the terms of the GNU Lesser General Public License as
%% published by the Free Software Foundation; either version 2 of the
%% License, or (at your option) any later version.
%%
%% This document file is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
%% General Public License for more details.
%%
%% You should have received a copy of the GNU Lesser General Public License
%% along with this document file; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
%% USA.
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{fixed-algorithmic}
[2009/08/24 v0.1 Document Style `algorithmic']
% The algorithmic.sty package:
\RequirePackage{ifthen}
\RequirePackage{keyval}
\newboolean{ALC@noend}
\setboolean{ALC@noend}{false}
\newcounter{ALC@unique} % new counter to make lines numbers be internally
\setcounter{ALC@unique}{0} % different in different algorithms
\newcounter{ALC@line} % counter for current line
\newcounter{ALC@rem} % counter for lines not printed
\newcounter{ALC@depth}
\newlength{\ALC@tlm}
%
\DeclareOption{noend}{\setboolean{ALC@noend}{true}}
%
\ProcessOptions
%
% For keyval-style options
\def\algsetup{\setkeys{ALG}}
%
% For indentation of algorithms
\newlength{\algorithmicindent}
\setlength{\algorithmicindent}{0pt}
\define@key{ALG}{indent}{\setlength{\algorithmicindent}{#1}}
\ifthenelse{\lengthtest{\algorithmicindent=0pt}}%
{\setlength{\algorithmicindent}{1em}}{}
%
% For line numbers' delimiters
\newcommand{\ALC@linenodelimiter}{:}
\define@key{ALG}{linenodelimiter}{\renewcommand{\ALC@linenodelimiter}{#1}}
%
% For line numbers' size
\newcommand{\ALC@linenosize}{\footnotesize}
\define@key{ALG}{linenosize}{\renewcommand{\ALC@linenosize}{#1}}
%
% ALGORITHMIC
\newcommand{\algorithmicrequire}{\textbf{Require:}}
\newcommand{\algorithmicensure}{\textbf{Ensure:}}
\newcommand{\algorithmiccomment}[1]{\{#1\}}
\newcommand{\algorithmicend}{\textbf{end}}
\newcommand{\algorithmicif}{\textbf{if}}
\newcommand{\algorithmicthen}{\textbf{then}}
\newcommand{\algorithmicelse}{\textbf{else}}
\newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
\newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}
\newcommand{\algorithmicfor}{\textbf{for}}
\newcommand{\algorithmicforall}{\textbf{for all}}
\newcommand{\algorithmicdo}{\textbf{do}}
\newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}
\newcommand{\algorithmicwhile}{\textbf{while}}
\newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}
\newcommand{\algorithmicloop}{\textbf{loop}}
\newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}
\newcommand{\algorithmicrepeat}{\textbf{repeat}}
\newcommand{\algorithmicuntil}{\textbf{until}}
\newcommand{\algorithmicprint}{\textbf{print}}
\newcommand{\algorithmicreturn}{\textbf{return}}
\newcommand{\algorithmicand}{\textbf{and}}
\newcommand{\algorithmicor}{\textbf{or}}
\newcommand{\algorithmicxor}{\textbf{xor}}
\newcommand{\algorithmicnot}{\textbf{not}}
\newcommand{\algorithmicto}{\textbf{to}}
\newcommand{\algorithmicinputs}{\textbf{inputs}}
\newcommand{\algorithmicoutputs}{\textbf{outputs}}
\newcommand{\algorithmicglobals}{\textbf{globals}}
\newcommand{\algorithmicbody}{\textbf{do}}
\newcommand{\algorithmictrue}{\textbf{true}}
\newcommand{\algorithmicfalse}{\textbf{false}}
\def\ALC@item[#1]{%
\if@noparitem \@donoparitem
\else \if@inlabel \indent \par \fi
\ifhmode \unskip\unskip \par \fi
\if@newlist \if@nobreak \@nbitem \else
\addpenalty\@beginparpenalty
\addvspace\@topsep \addvspace{-\parskip}\fi
\else \addpenalty\@itempenalty \addvspace\itemsep
\fi
\global\@inlabeltrue
\fi
\everypar{\global\@minipagefalse\global\@newlistfalse
\if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
\penalty\z@ \fi
\everypar{}}\global\@nobreakfalse
\if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
\sbox\@tempboxa{\makelabel{#1}}%
\global\setbox\@labels
\hbox{\unhbox\@labels \hskip \itemindent
\hskip -\labelwidth \hskip -\ALC@tlm
\ifdim \wd\@tempboxa >\labelwidth
\box\@tempboxa
\else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
\hskip \ALC@tlm}\ignorespaces}
%
\newenvironment{algorithmic}[1][0]{%
\setcounter{ALC@depth}{\@listdepth}%
\let\@listdepth\c@ALC@depth
\let\@item\ALC@item
\newcommand{\ALC@lno}{%
\ifthenelse{\equal{\arabic{ALC@rem}}{0}}%
{{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}}{}%
}%
\let\@listii\@listi
\let\@listiii\@listi
\let\@listiv\@listi
\let\@listv\@listi
\let\@listvi\@listi
\let\@listvii\@listi
\newenvironment{ALC@g}{%
\begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
\listparindent\z@ \rightmargin\z@
\topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
\leftmargin \algorithmicindent%1em
\addtolength{\ALC@tlm}{\leftmargin}%
}%
}%
{\end{list}}
\newcommand{\ALC@it}{%
\stepcounter{ALC@rem}%
\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}%
\stepcounter{ALC@line}%
\refstepcounter{ALC@unique}%
\item\def\@currentlabel{\theALC@line}%
}%
\newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
{}{\ \algorithmiccomment{##1}}}%
\newcommand{\REQUIRE}{\item[\algorithmicrequire]}%
\newcommand{\ENSURE}{\item[\algorithmicensure]}%
\newcommand{\PRINT}{\ALC@it\algorithmicprint{} \ }%
\newcommand{\RETURN}{\ALC@it\algorithmicreturn{} \ }%
\newcommand{\TRUE}{\algorithmictrue{}}%
\newcommand{\FALSE}{\algorithmicfalse{}}%
\newcommand{\AND}{\algorithmicand{} }%
\newcommand{\OR}{\algorithmicor{} }%
\newcommand{\XOR}{\algorithmicxor{} }%
\newcommand{\NOT}{\algorithmicnot{} }%
\newcommand{\TO}{\algorithmicto{} }%
\newcommand{\STATE}{\ALC@it}%
\newcommand{\STMT}{\ALC@it}%
\newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}%
\newenvironment{ALC@inputs}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@outputs}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@globals}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@body}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}%
\newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}%
\renewcommand{\\}{\@centercr}%
\newcommand{\INPUTS}[1][default]{\ALC@it\algorithmicinputs\ \ALC@com{##1}\begin{ALC@inputs}}%
\newcommand{\ENDINPUTS}{\end{ALC@inputs}}%
\newcommand{\OUTPUTS}[1][default]{\ALC@it\algorithmicoutputs\ \ALC@com{##1}\begin{ALC@outputs}}%
\newcommand{\ENDOUTPUTS}{\end{ALC@outputs}}%
\newcommand{\GLOBALS}{\ALC@it\algorithmicglobals\ }%
\newcommand{\BODY}[1][default]{\ALC@it\algorithmicbody\ \ALC@com{##1}\begin{ALC@body}}%
\newcommand{\ENDBODY}{\end{ALC@body}}%
\newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen
\ALC@com{##1}\begin{ALC@if}}%
\newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse
\ALC@com{##1}\begin{ALC@if}}%
\newcommand{\ELSIF}[2][default]%
{\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen
\ALC@com{##1}\begin{ALC@if}}%
\newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo
\ALC@com{##1}\begin{ALC@for}}%
\newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
\algorithmicdo
\ALC@com{##1}\begin{ALC@for}}%
\newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
\algorithmicdo
\ALC@com{##1}\begin{ALC@whl}}%
\newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop
\ALC@com{##1}\begin{ALC@loop}}%
\newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat
\ALC@com{##1}\begin{ALC@rpt}}%
\newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}%
\ifthenelse{\boolean{ALC@noend}}{%
\newcommand{\ENDIF}{\end{ALC@if}}%
\newcommand{\ENDFOR}{\end{ALC@for}}%
\newcommand{\ENDWHILE}{\end{ALC@whl}}%
\newcommand{\ENDLOOP}{\end{ALC@loop}}%
}{%
\newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}%
\newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}%
\newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}%
\newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}%
}%
\renewcommand{\@toodeep}{}%
\begin{list}{\ALC@lno}{\setcounter{ALC@rem}{0}\setcounter{ALC@line}{0}%
\itemsep\z@ \itemindent\z@ \listparindent\z@
\partopsep\z@ \parskip\z@ \parsep\z@
\labelsep 0.5em \topsep 0.2em
\ifthenelse{\equal{#1}{0}}%
{\labelwidth 0.5em }%
{\labelwidth 1.2em }%
\leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}%
\ALC@tlm\labelsep
}%
}%
{\end{list}}
\endinput
%%
%% End of file `algorithmic.sty'.
Jetzt druckt Sie Beispiel (mit \usepackage{fixed-algorithmic}
)
Hier ist die diff
der beiden Dateien (die erste ist die korrigierte):
123c123
< \newenvironment{algorithmic}[1][0]{%
---
> \newenvironment{algorithmic}[1][0]{
125,126c125,126
< \let\@listdepth\c@ALC@depth
< \let\@item\ALC@item
---
> \let\@listdepth\c@ALC@depth%
> \let\@item\ALC@item%
128c128
< \ifthenelse{\equal{\arabic{ALC@rem}}{0}}%
---
> \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
130c130
< }%
---
> }
137c137
< \newenvironment{ALC@g}{%
---
> \newenvironment{ALC@g}{
142,144c142,144
< \addtolength{\ALC@tlm}{\leftmargin}%
< }%
< }%
---
> \addtolength{\ALC@tlm}{\leftmargin}
> }
> }
152c152
< }%
---
> }
154,189c154,189
< {}{\ \algorithmiccomment{##1}}}%
< \newcommand{\REQUIRE}{\item[\algorithmicrequire]}%
< \newcommand{\ENSURE}{\item[\algorithmicensure]}%
< \newcommand{\PRINT}{\ALC@it\algorithmicprint{} \ }%
< \newcommand{\RETURN}{\ALC@it\algorithmicreturn{} \ }%
< \newcommand{\TRUE}{\algorithmictrue{}}%
< \newcommand{\FALSE}{\algorithmicfalse{}}%
< \newcommand{\AND}{\algorithmicand{} }%
< \newcommand{\OR}{\algorithmicor{} }%
< \newcommand{\XOR}{\algorithmicxor{} }%
< \newcommand{\NOT}{\algorithmicnot{} }%
< \newcommand{\TO}{\algorithmicto{} }%
< \newcommand{\STATE}{\ALC@it}%
< \newcommand{\STMT}{\ALC@it}%
< \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}%
< \newenvironment{ALC@inputs}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@outputs}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@globals}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@body}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}%
< \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}%
< \renewcommand{\\}{\@centercr}%
< \newcommand{\INPUTS}[1][default]{\ALC@it\algorithmicinputs\ \ALC@com{##1}\begin{ALC@inputs}}%
< \newcommand{\ENDINPUTS}{\end{ALC@inputs}}%
< \newcommand{\OUTPUTS}[1][default]{\ALC@it\algorithmicoutputs\ \ALC@com{##1}\begin{ALC@outputs}}%
< \newcommand{\ENDOUTPUTS}{\end{ALC@outputs}}%
< \newcommand{\GLOBALS}{\ALC@it\algorithmicglobals\ }%
< \newcommand{\BODY}[1][default]{\ALC@it\algorithmicbody\ \ALC@com{##1}\begin{ALC@body}}%
< \newcommand{\ENDBODY}{\end{ALC@body}}%
< \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen
< \ALC@com{##1}\begin{ALC@if}}%
< \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse
< \ALC@com{##1}\begin{ALC@if}}%
---
> {}{\ \algorithmiccomment{##1}}}
> \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
> \newcommand{\ENSURE}{\item[\algorithmicensure]}
> \newcommand{\PRINT}{\ALC@it\algorithmicprint{} \ }
> \newcommand{\RETURN}{\ALC@it\algorithmicreturn{} \ }
> \newcommand{\TRUE}{\algorithmictrue{}}
> \newcommand{\FALSE}{\algorithmicfalse{}}
> \newcommand{\AND}{\algorithmicand{} }
> \newcommand{\OR}{\algorithmicor{} }
> \newcommand{\XOR}{\algorithmicxor{} }
> \newcommand{\NOT}{\algorithmicnot{} }
> \newcommand{\TO}{\algorithmicto{} }
> \newcommand{\STATE}{\ALC@it}
> \newcommand{\STMT}{\ALC@it}
> \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
> \newenvironment{ALC@inputs}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@outputs}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@globals}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@body}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
> \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
> \renewcommand{\\}{\@centercr}
> \newcommand{\INPUTS}[1][default]{\ALC@it\algorithmicinputs\ \ALC@com{##1}\begin{ALC@inputs}}
> \newcommand{\ENDINPUTS}{\end{ALC@inputs}}
> \newcommand{\OUTPUTS}[1][default]{\ALC@it\algorithmicoutputs\ \ALC@com{##1}\begin{ALC@outputs}}
> \newcommand{\ENDOUTPUTS}{\end{ALC@outputs}}
> \newcommand{\GLOBALS}{\ALC@it\algorithmicglobals\ }
> \newcommand{\BODY}[1][default]{\ALC@it\algorithmicbody\ \ALC@com{##1}\begin{ALC@body}}
> \newcommand{\ENDBODY}{\end{ALC@body}}
> \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
> \ALC@com{##1}\begin{ALC@if}}
> \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
> \ALC@com{##1}\begin{ALC@if}}
191,194c191,194
< {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen
< \ALC@com{##1}\begin{ALC@if}}%
< \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo
< \ALC@com{##1}\begin{ALC@for}}%
---
> {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
> \ALC@com{##1}\begin{ALC@if}}
> \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
> \ALC@com{##1}\begin{ALC@for}}
196,197c196,197
< \algorithmicdo
< \ALC@com{##1}\begin{ALC@for}}%
---
> \algorithmicdo%
> \ALC@com{##1}\begin{ALC@for}}
199,217c199,217
< \algorithmicdo
< \ALC@com{##1}\begin{ALC@whl}}%
< \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop
< \ALC@com{##1}\begin{ALC@loop}}%
< \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat
< \ALC@com{##1}\begin{ALC@rpt}}%
< \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}%
< \ifthenelse{\boolean{ALC@noend}}{%
< \newcommand{\ENDIF}{\end{ALC@if}}%
< \newcommand{\ENDFOR}{\end{ALC@for}}%
< \newcommand{\ENDWHILE}{\end{ALC@whl}}%
< \newcommand{\ENDLOOP}{\end{ALC@loop}}%
< }{%
< \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}%
< \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}%
< \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}%
< \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}%
< }%
< \renewcommand{\@toodeep}{}%
---
> \algorithmicdo%
> \ALC@com{##1}\begin{ALC@whl}}
> \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
> \ALC@com{##1}\begin{ALC@loop}}
> \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
> \ALC@com{##1}\begin{ALC@rpt}}
> \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
> \ifthenelse{\boolean{ALC@noend}}{
> \newcommand{\ENDIF}{\end{ALC@if}}
> \newcommand{\ENDFOR}{\end{ALC@for}}
> \newcommand{\ENDWHILE}{\end{ALC@whl}}
> \newcommand{\ENDLOOP}{\end{ALC@loop}}
> }{
> \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
> \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
> \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
> \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
> }
> \renewcommand{\@toodeep}{}
219,225c219,225
< \itemsep\z@ \itemindent\z@ \listparindent\z@
< \partopsep\z@ \parskip\z@ \parsep\z@
< \labelsep 0.5em \topsep 0.2em
< \ifthenelse{\equal{#1}{0}}%
< {\labelwidth 0.5em }%
< {\labelwidth 1.2em }%
< \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}%
---
> \itemsep\z@ \itemindent\z@ \listparindent\z@%
> \partopsep\z@ \parskip\z@ \parsep\z@%
> \labelsep 0.5em \topsep 0.2em%
> \ifthenelse{\equal{#1}{0}}
> {\labelwidth 0.5em }
> {\labelwidth 1.2em }
> \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}
227,228c227,228
< }%
< }%
---
> }
> }
Antwort3
Hier ist eine mögliche Lösung mit demtikzpagenodes
Paket und dietikzmark
Bibliothek, um die Kommentare bündig am rechten Rand zu platzieren:
\documentclass{article}
\usepackage{algorithmic}
\usepackage{showframe}
\usepackage{eqparbox}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{mycomm}
\renewcommand{\algorithmiccomment}[1]{%
\stepcounter{mycomm}%
\tikzmark{start-\themycomm}%
\tikz[remember picture,overlay]
\node[inner sep=0pt,outer sep=0pt,anchor=east]
at (current page text area.east|-{pic cs:start-\themycomm})
{\eqparbox{COMMENT}{\{#1\}}};
}
\begin{document}
\begin{algorithmic}
\STATE something \COMMENT{first comment}
\IF[second comment]{some condition}
\STATE some other thing \COMMENT{third comment}
\IF[fourth comment]{some condition}
\STATE final thing \COMMENT{some final thoughts}
\ENDIF
\ENDIF
\end{algorithmic}
\end{document}