How to put Curly Brace around only part of array

So currently I have curly braces around an array with vertical bars next to only parts of an array using \multicolumn:

$f_{i_k}(a)= \left\{ \begin{array}{|c|c|c|r} \multicolumn{1}{c}{k=1} & \multicolumn{1}{c}{k=2} & \multicolumn{1}{c}{k=3} \\ A'(a), & B(a), & C(a), &i=1 \\ A(a), & B'(a), & C(a), &i=2 \\ A(a), & B(a), & C'(a), &i=3 \end{array} \right.$


which gives me this:

However I want the curly brace to only extend around the the rows with vertical bars, i.e. the bottom three rows.

Any ideas on how I'd do this? simply putting \left\{ and \right. within the array does not seem to work

2 Answers

This is a solution using nested arrays and involves manual adjustments. I'll provide another automatic solution with blkarray package.

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

$f_{i_k}(a)= \begin{array}{c} \begin{array}{cccr} k = 1 & \,k = 2\, & \,k = 3 & \hspace{1.2em} \\ \end{array}\\ \left \{ \begin{array}{|c|c|c|r} A'(a), & B(a), & C(a), &i=1 \\ A(a), & B'(a), & C(a), &i=2 \\ A(a), & B(a), & C'(a), &i=3 \end{array} \right. \end{array}$

\end{document}


Using \usepackage{blkarray}, this is another option:

$f_{i_k}(a) = \begin{blockarray}{ccccr} &k=1 & k=2 & k=3 & \\ \begin{block}{@{}c\{@{}|c|c|c|r} &A'(a), & B(a) , & C(a) , & i=1 \\ &A(a) , & B'(a), & C(a) , & i=2 \\ &A(a) , & B(a) , & C'(a), & i=3 \\ \end{block} \end{blockarray}$


with a slightly different result:

Here is a solution with {NiceArray} of nicematrix.

I have used {NiceArray} with the key first-row, and, so, there is no vertical rules in that first-row''.

For the vertical brace, I have used the command \SubMatrix available in the \CodeAfter of the environment {NiceArray}.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$f_{i_k}(a)= \quad \begin{NiceArray}{|c|c|c|r}[first-row] k=1 & k=2 & k=3 \\ A'(a), & B(a), & C(a), &i=1 \\ A(a), & B'(a), & C(a), &i=2 \\ A(a), & B(a), & C'(a), &i=3 \CodeAfter \SubMatrix{\{}{1-1}{3-1}{.}[left-xshift=0.5em] \end{NiceArray}$

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes).

If you prefer to align the equality with the brace, use the key baseline:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$f_{i_k}(a)= \quad \begin{NiceArray}{|c|c|c|r}[first-row,baseline=2] k=1 & k=2 & k=3 \\ A'(a), & B(a), & C(a), &i=1 \\ A(a), & B'(a), & C(a), &i=2 \\ A(a), & B(a), & C'(a), &i=3 \CodeAfter \SubMatrix{\{}{1-1}{3-1}{.}[left-xshift=0.5em] \end{NiceArray}$

\end{document}