31

I'm trying to write

^nP_k=\frac{n!}{(n-k)!}  
\binom nk=^nC_k=\frac{n!}{k!(n-k)!}

but when compiled the n is a little far away from the P and C for my liking. Is there a command to write this? I know there is a \binom so I was hopeful. If not, is there a way to force the n to be closer?

\documentclass{article}  
\begin{document}  
$ ^nP_k=\frac{n!}{(n-k}!} - permutation \\  
\binom nk=^nC_k=\frac{n!}{k!(n-k)!} - combination $  
end{document}
jub0bs
  • 58,916
DannyBland
  • 1,141

3 Answers3

31

You could use the \prescript command from the mathtools package and define two commands; something along the following lines:

\documentclass{article}
\usepackage{mathtools}

\newcommand\Myperm[2][^n]{\prescript{#1\mkern-2.5mu}{}P_{#2}}
\newcommand\Mycomb[2][^n]{\prescript{#1\mkern-0.5mu}{}C_{#2}}

\begin{document}

\[
\Myperm{k} = \frac{n!}{(n-k)!}\quad
\Mycomb{k} = \frac{n!}{k!(n-k)!}\quad
\Myperm[m]{k} = \frac{m!}{(m-k)!}\quad
\Mycomb[m]{k} = \frac{m!}{k!(m-k)!}\quad
\]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • It's not on topic, I've just noticed \qquad a few times and wondered what it is? – DannyBland Apr 06 '13 at 00:55
  • 1
    @DannyBland \qquad introduces (both in text and in math mode) a space equal to twice \quad. – Gonzalo Medina Apr 06 '13 at 00:57
  • 2
    If you want to write \Myperm{x}{y} instead of \Myperm[x]{y} (different brackets) and are okay not having n as the default first parameter, remove[n] from both the \newcommand lines. – Gordon Gustafson Sep 04 '14 at 20:01
  • You might also prefer the \cramped style for this, to reduce how much the scripts are raised and lowered. – Davislor May 27 '20 at 00:53
  • I tried using this with the kaobook class and am getting the error LaTeX Error: Command \refeq already defined. Any ideas how to fix this? – EthanAlvaree Aug 18 '21 at 08:35
30

You can define your own:

enter image description here

Code:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\Perm}[2]{{}^{#1}!P_{#2}}% \newcommand{\Comb}[2]{{}^{#1}C_{#2}}%

\begin{document}
$\Perm{n}{k}=\frac{n!}{(n-k)!}$ - permutation

$\binom nk=\Comb{n}{k}=\frac{n!}{k!(n-k)!}$ - combination
\end{document}

Peter Grill
  • 223,288
11

I provide a generic \permcomb macro that will be used to setup \perm and \comb.

The spacing is between the prescript and the following character is kerned with the help of \mkern.

The default kerning between the prescript and P is -3mu, and -1mu with C, which can be changed by using the optional argument of all three macros.

Code

\documentclass{article}
\usepackage{amsmath}
\newcommand*{\permcomb}[4][0mu]{{{}^{#3}\mkern#1#2_{#4}}}
\newcommand*{\perm}[1][-3mu]{\permcomb[#1]{P}}
\newcommand*{\comb}[1][-1mu]{\permcomb[#1]{C}}
\begin{document}
$\perm{n}{k}$

$\comb{n}{k}$

$\permcomb[-3mu]{J}{l}{k}$
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821