
Para o algoritmo a seguir, obtenho quatro espaços para cada linha de texto dentro do loop. Como posso conseguir apenas duas ou três vagas? Algumas das minhas linhas de texto vão para a próxima linha. Quero economizar alguns espaços horizontais.
\usepackage[noline,boxruled,commentsnumbered,linesnumbered,titlenumbered]{algorithm2e}
\IncMargin{0.5em}
\begin{algorithm}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\SetKwFor{Foreach}{for each}{do}{endfor}
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
\BlankLine
\Input{A method \emph{m}}
\Output{result}
\BlankLine
\Foreach { $x \in M_{x}$}{
do something
}
\caption{Algorithm}\label{Method}
\end{algorithm}
Responder1
Usar
\SetInd{<space before>}{<space after>}
para controlar o espaçamento antes e depois da régua vertical (que é desabilitada por meio dessa noline
opção). Aqui está uma comparação da configuração padrão e outra com \SetInd{0.25em}{0.1em}
:
Código:
\documentclass{article}
\usepackage[noline,boxruled,commentsnumbered,linesnumbered,titlenumbered]{algorithm2e}
\IncMargin{0.5em}
\begin{document}
\noindent
Without setting \verb|\SetInd{}{}|:
\begin{algorithm}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\SetKwFor{Foreach}{for each}{do}{endfor}
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
\BlankLine
\Input{A method \emph{m}}
\Output{result}
\BlankLine
\Foreach { $x \in M_{x}$}{
do something
}
\caption{Algorithm}\label{Method}
\end{algorithm}
\noindent
With \verb|\SetInd{0.25em}{0.1em}|:
\SetInd{0.25em}{0.1em}
\begin{algorithm}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\SetKwFor{Foreach}{for each}{do}{endfor}
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
\BlankLine
\Input{A method \emph{m}}
\Output{result}
\BlankLine
\Foreach { $x \in M_{x}$}{
do something
}
\caption{Algorithm}\label{Method}
\end{algorithm}
\end{document}