# Typesetting permutations and alignment

I am typesetting some permutations and am trying to highlight how their cycle structures interact because of how they overlap. Because of this, I want them to fit nicely into a grid. I've approximated what I would like, but there is an issue about parentheses.

(I've suppressed some of the parentheses for clarity whenever the permutation has a fixed point.) I would like for the numbers to be exactly in columns and for the parentheses to fill in the gaps. (So that all the 7's would be aligned, and the parenthesis for the second 7 would be slightly off to the side. Here is my current code:

$\setlength{\arraycolsep}{2pt} \begin{matrix} (1 & 2 & 3 & 4 & 5)&(6 & 7 & 8 & 9 & 10) \\ 1 & 2 & (3 & 4 & 5&6 & 7) & 8 & 9 & 10\\ 1 & 2 & 3 & (4 & 5&6 & 7 & 8) & 9 & 10 \end{matrix}$


I have also tried inserting columns between every pair of numbers as places to insert parentheses, but then the whole arrays gets too spaced out horizontally.

Any suggestions would be appreciated!

\documentclass{article}
\usepackage{amsmath}
\begin{document}

$\setlength{\arraycolsep}{4pt} \begin{matrix} \llap{(}1 & 2 & 3 & 4 & 5\rlap{)}&\llap{(}6 & 7 & 8 & 9 & 10\rlap{)} \\ 1 & 2 & \llap{(}3 & 4 & 5&6 & 7\rlap{)} & 8 & 9 & 10\\ 1 & 2 & 3 & \llap{(}4 & 5&6 & 7 & 8\rlap{)} & 9 & 10 \end{matrix}$
\end{document}


To take David's excellent answer a step further...if the matrix is large, it can get tiring to type in all the \llaps and \rlaps. Thus, one can make ( and ) active and take care of the laps automatically. After the initial setup, input is simplified.

\documentclass{article}
\usepackage{amsmath}
\let\svlp(
\let\svrp)
\begin{document}

$\setlength{\arraycolsep}{4pt} \catcode(=\active \def({\llap{\svlp}} \catcode)=\active \def){\rlap{\svrp}} \begin{matrix}(1 & 2 & 3 & 4 & 5)&(6 & 7 & 8 & 9 & 10) \\ 1 & 2 & (3 & 4 & 5&6 & 7) & 8 & 9 & 10\\ 1 & 2 & 3 & (4 & 5&6 & 7 & 8) & 9 & 10 \end{matrix}$
\end{document}


• What's the apparently empty \def\activate for? – Thruston Jan 14 '17 at 14:55
• @Thruston Oops. That was just detritus. Now removed. – Steven B. Segletes Jan 14 '17 at 16:26

A solution with blkarray:

\documentclass{article}
\usepackage{mathtools}
\usepackage{blkarray}%

\begin{document}

$\makeatletter \BA@colsep=3pt \makeatother \begin{blockarray}{*{10}{c}} \begin{block}{(*{5}{c})(*{5}{c})} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\ \end{block} \begin{block}{cc(*{5}{c})ccc} 1 & 2 & 3 & 4 & 5&6 & 7 & 8 & 9 & 10\\ \end{block} \begin{block}{ccc(*{5}{c})cc} 1 & 2 & 3 & 4 & 5 &6 & 7 & 8 & 9 & 10_\\ \end{block} \end{blockarray}$

\end{document}


• who wrote that package:-) – David Carlisle Jan 13 '17 at 23:54
• Blessings and praises be given to you, mylord! – Bernard Jan 14 '17 at 0:09
• Missing a left paren on line 1 – Scott Seidman Jan 14 '17 at 1:11