我希望将算法中的线条与某个符号对齐。例如:
long_variable_name = k | long_variable_name = k
variable = l | variable = l
就 LaTeX 而言,我有以下示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}
\begin{document}
% ALGORITHM PARAMETERS %
\SetAlFnt{\small\fontfamily{cmr}}
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\RestyleAlgo{boxed}
\LinesNumbered
\IncMargin{1em}
\begin{algorithm}
\footnotesize
\DontPrintSemicolon
\SetKwData{VARA}{VAR$_{old}$}
\SetKwData{VARB}{VAR$_{new}$}
\SetKwData{TEMP}{tmp$_{cc}$}
\Input{ A matrix N$\times$M}
\Output{ A number K}
\BlankLine
\VARA \ := \ 123 \\
\VARB \ := \ 123 \\
\TEMP \ := \ 423 \\
\end{algorithm}
\end{document}
VARA
VARB
我希望对齐符号上分配了和TEMP
值的线条:=
。可以这样做吗?提前谢谢
附言:
这是代码的输出
答案1
您可以使用 eqparbox,这需要两次编译。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}
\usepackage{eqparbox}
\begin{document}
% ALGORITHM PARAMETERS %
\SetAlFnt{\small\fontfamily{cmr}}
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\RestyleAlgo{boxed}
\LinesNumbered
\IncMargin{1em}
\begin{algorithm}
\footnotesize
\DontPrintSemicolon
\SetKwData{VARA}{\eqmakebox[var][l]{VAR$_{\mathit{old}}$}}
\SetKwData{VARB}{\eqmakebox[var][l]{VAR$_{\mathit{new}}$}}
\SetKwData{TEMP}{\eqmakebox[var][l]{tmp$_{\mathit{cc}}$}}
\Input{ A matrix N$\times$M}
\Output{ A number K}
\BlankLine
\VARA \ := \ 123 \\
\VARB \ := \ 123 \\
\TEMP \ := \ 423 \\
\end{algorithm}
\end{document}