2

I have four math function definitions, and I want to center them, such that function names start from the same point, and after the colon there is some blank space before the domain and range is defined. Currently, I have this code segment:

\documentclass{paper}
\begin{document}

\begin{center}
$\mathsf{Gen}: \mathbb{N} \rightarrow \mathcal{K}_p \times \mathcal{K}_s \times \mathcal{K}_e$

$\mathsf{Enc}: \mathcal{K}_p \times \mathcal{P} \rightarrow \mathcal{X}$

$\mathsf{Dec}: \mathcal{K}_s \times \mathcal{Z} \rightarrow \mathcal{P}$

$\mathsf{Eval}: \mathcal{K}_e \times \mathcal{C} \times \mathcal{Z^*} \rightarrow \mathcal{Y}$
\end{center}

\end{document}

But this results in a kind of distorted output. I want the output to look like this:

enter image description here

Any ideas how to achieve it? Please note that the whole group of equations should also be centered in the page.

1
  • 1
    ! Undefined control sequence. l.5 $\mathsf{Gen}: \mathbb Dec 29 '16 at 21:29
6

perhaps with align

enter image description here

\documentclass{paper}
\usepackage{amsmath,amsfonts}
\begin{document}

\begin{align*}
\mathsf{Gen}:&& \mathbb{N} &\rightarrow \mathcal{K}_p \times \mathcal{K}_s \times \mathcal{K}_e\\
\mathsf{Enc}:&& \mathcal{K}_p \times \mathcal{P} &\rightarrow \mathcal{X}\\
\mathsf{Dec}:&& \mathcal{K}_s \times \mathcal{Z} &\rightarrow \mathcal{P}\\
\mathsf{Eval}:&& \mathcal{K}_e \times \mathcal{C} \times \mathcal{Z^*} &\rightarrow \mathcal{Y}
\end{align*}

\end{document}
0
4

A variant with align, and another with alignat:

\documentclass{paper}
\usepackage{amsmath,amsfonts}
\begin{document}

\begin{align*}
    & \mathsf{Gen}: & \mathbb{N} & → \mathcal{K}_p × \mathcal{K}_s × \mathcal{K}_e & & \\
  & \mathsf{Enc}:& \mathcal{K}_p × \mathcal{P} & → \mathcal{X}\\
  & \mathsf{Dec}:& \mathcal{K}_s × \mathcal{Z} & → \mathcal{P}\\
  & \mathsf{Eval}:& \mathcal{K}_e × \mathcal{C} × \mathcal{Z^*} & → \mathcal{Y}
\end{align*}

\begin{alignat*}{2}
    & \mathsf{Gen}: & \hspace{5em} & \mathbb{N} → \mathcal{K}_p × \mathcal{K}_s × \mathcal{K}_e \\
    & \mathsf{Enc}: & & \mathcal{K}_p × \mathcal{P} → \mathcal{X} \\
    & \mathsf{Dec}: & & \mathcal{K}_s × \mathcal{Z} → \mathcal{P} \\
    & \mathsf{Eval}: & & \mathcal{K}_e × \mathcal{C} × \mathcal{Z^*} → \mathcal{Y}
\end{alignat*}

\end{document} 

enter image description here

7
  • 1
    Why have three & in each line in the first block of equations while using align*? Jan 2 '17 at 15:07
  • 1
    Because there are two alignment points. n alignment points require 2n – 1 ampersands.
    – Bernard
    Jan 2 '17 at 15:14
  • If there are two alignment points, shouldn't you only use {alignat*}{2} then, as in the latter construction? (David has done the same as you, but I don't understand why.) Jan 2 '17 at 15:33
  • 1
    alignat (which I use in the second code) adds the possibility to control the spacing between the alignment groups. That is the reason for \hspace{5em}.
    – Bernard
    Jan 2 '17 at 15:42
  • 1
    @soodehMehboodi: Why not simply $2\mathbb{Z}^{+}$ (or $2\mathbf{Z}^{+}$)?
    – Bernard
    Jan 9 '20 at 19:20
2

Here is how I would do it:

\documentclass{paper}

\usepackage{amsmath}
\usepackage{amsfonts}

\newcommand*\name[1]{\text{$\mathsf{#1}$:}}
\newcommand*\letter[1]{\mathcal{#1}}

\begin{document}

\begin{alignat*}{2}
  &\name{Gen}  &       \mathbb{N}     \times \letter{A}                          &\to \letter{K}_{p} \times \letter{K}_{s} \times \letter{K}_{e},\\
  &\name{Enc}  &       \letter{K}_{p} \times \letter{P}                          &\to \letter{X},\\
  &\name{Dec}  &       \letter{K}_{s} \times \letter{Z}                          &\to \letter{P},\\
  &\name{Eval} &\qquad \letter{K}_{e} \times \letter{C} \times \letter{Z}^{\ast} &\to \letter{Y}.
\end{alignat*}

\end{document}

output

Notice the removal of space between the words/abbreviations and the colons.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.