# 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

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: 