# How do I create and indent “preamble” sections in algorithms?

I am using algorithm2e to write algorithms. I'm doing things in such a way that, before the actual algorithm, I have a section for input and output arguments, and when relevant, references to other algorithms and equations that may be far away in the document. Like so:

I have introduced the "preamble" section of references with \SetKwInput{KwRef}{Referências}. So far so good.

But the way I'm doing it seems not to be the most clever way. I'm using \quad at the beginning of every item:

\begin{algorithm}
\caption{My example}
\KwIn{\\
\quad$X$: something\\
\quad$Y$: something else
}
\KwOut{\\
\quad$R$: the result
}
\KwRef{\\
\quad$f(\cdot)$ is the function introduced in Equation~\ref{eq:znorm}
}
$R \leftarrow X + Y$\;
\end{algorithm}


What's the smart way of doing it?

You could instead perform the placement of \quad automatically via a tabular; this seems to fit in with your current usage:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}

\renewcommand{\KwIn}[1]{%
\KwIna{\strut\\ \quad\begin{tabular}{@{} l @{}} #1 \end{tabular}}}
\renewcommand{\KwOut}[1]{%
\KwOuta{\strut\\ \quad\begin{tabular}{@{} l @{}} #1 \end{tabular}}}
\newcommand{\KwRef}[1]{%
\KwRefa{\strut\\ \quad\begin{tabular}{@{} l @{}} #1 \end{tabular}}}
\SetKwInput{KwOuta}{Parâmetros de Saída}
\SetKwInput{KwRefa}{Referências}

\begin{document}

\begin{algorithm}
\caption{My example}
\KwIn{%
$X$: something \\
$Y$: something else
}
\KwOut{%
$R$: the result
}
\KwRef{%
$f(\cdot)$ is the function introduced in Equation~\ref{eq:znorm}
}
$R \leftarrow X + Y$\;
\end{algorithm}

\renewcommand{\theequation}{2.3}% Just for this example
$$f(x) = ax^2 + bx + c \label{eq:znorm}$$

\end{document}

• It works, but... how? – giusti Jan 28 '17 at 0:34
• The argument supplied to \KwIn (and friends) is placed inside a tabular. Using \\ to line-break the content translates well to the tabular environment. Each command inserts \\, followed by a \quad and the tabular. The tabular sets its content left aligned (without a prepended space, due to @{}). – Werner Jan 28 '17 at 7:17
• Ah, so maybe what you actually meant is that I could automatically add a \quad and insert the lines into a tabular? I was thinking that somehow this command was inserting several \quads: one for each line of the tabular environment. – giusti Jan 28 '17 at 14:28