
Para el siguiente algoritmo, obtengo cuatro espacios para cada línea de texto dentro del bucle. ¿Cómo puedo conseguir sólo dos o tres espacios? Algunas de mis líneas de texto pasan a la siguiente línea. Quiero guardar algunos espacios horizontales.
\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}
Respuesta1
Usar
\SetInd{<space before>}{<space after>}
para controlar el espaciado antes y después de la regla vertical (que se desactiva a través de esa noline
opción). Aquí hay una comparación de la configuración predeterminada y otra con \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}