# How can I denote column and row names in a matrix and align equations with that matrix?

I want to typeset a large matrix that represents a generalized case of something. I have difficulty doing the following:

1. Typing a set of letters near columns and rows that identify them
2. The matrix is too big so it cannot be centered to the middle of the text. I would like to temporarily increase the margins so that the matrix can be align horizontally to the center
3. If possible, I would like Zorig to go exactly to the middle of the empty area in the matrix
4. Increase the display size of all elements in the matrix
5. It is a good if the dots are more uniformly distributed between the elements they separate

What I get:

What I am (roughly) looking for:

And my source code:

\documentclass[11pt, a4paper]{book}

\usepackage{amsmath}
\usepackage{amssymb, amsfonts}
\usepackage{graphicx}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

% \begin{aligned} % \left[ \begin{array}{c c c c c c c c c !{\vrule width 0.25mm}c} & & & & & Z_{1k} & \dotsm & Z_{1p} & \dotsm & Z_{1k} - Z_{1p} \\ & & \scalebox{3}{Z_{orig}} & & & \vdots & & \vdots & & \vdots \\ & & & & & Z_{lk} & \dotsm & Z_{lp} & \dotsm & Z_{lk} - Z_{lp} \\ & & & & & \vdots & & \vdots & & \vdots \\ Z_{k1} & \dotsm & \dotsm & Z_{km} & \dotsm & Z_{kk} & \dotsm & Z_{kp} & \dotsm & Z_{kk} - Z_{kp} \\ \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\ Z_{p1} & \dotsm & \dotsm & Z_{pm} & \dotsm & Z_{pk} & \dotsm & Z_{pp} & \dotsm & Z_{pk} - Z_{pp} \\ \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\ \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\ \Xcline{1-10}{0.25mm} Z_{k1} - Z_{p1} & \dotsm & \dotsm & Z_{km} - Z_{pm} & \dotsm & Z_{kk} - Z_{pk} & \dotsm & Z_{kp} - Z_{pp} & \dotsm & Z_{th, kp} + Z_{b} \\ \end{array} \right] & \\ Z_{th,kp} = Z_{kk} + Z_{pp} - Z_{kp} - Z_{pk} & \\ % \end{aligned} %

\end{document}


I realize that the same question was asked in Where is the \matrix command? and Label rows of a matrix by characters, but the solutions provided there do not seem to simultaneously allow for 1. drawing horizontal lines and 2. aligning the main matrix with smaller equation under it (see the figure above).

For typing a set of letters near columns and rows that identify them, use blkarray package. See, for example, here: How to write this array?.

To center your matrix which is bigger than line width, I've used \makebox[\textwidth][c]{...}. See, for example, here: Center figure that is wider than \textwidth.

To increase the display size of all elements in the matrix I used \large within a minipage.

For better alignment, I've used \rule[-1ex]{0ex}{3.7ex} and \hspace.

For the correct length of the horizontal line, see here: Horizontal cline lengths inside blkarray.

\documentclass[11pt, a4paper]{book}

\usepackage{amsmath}
\usepackage{amssymb, amsfonts}
\usepackage{graphicx}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{array}
\renewcommand{\arraystretch}{1.2}
\usepackage{blkarray}% see, for example, https://tex.stackexchange.com/questions/313214/how-to-write-this-array/313219#313219
\usepackage{mwe}% for testing purpose only
\begin{document}
\blindtext% for testing purpose only
\makebox[\textwidth][c]{%
\begin{minipage}{.86\paperwidth}\large
\setlength\aboverulesep{0pt}\setlength\belowrulesep{0pt}
\setlength\cmidrulewidth{0.5pt}% https://tex.stackexchange.com/questions/377273/horizontal-cline-lengths-inside-blkarray
$$\begin{blockarray}{ccccccccccc} & & & & & & k & & p & & q\\[1ex] \begin{block}{c[c c c c c c c c c @{\hspace{1em}}|@{\hspace{.5em}}c]} & & & & & & Z_{1k} & \dotsm & Z_{1p} & \dotsm & Z_{1k} - Z_{1p} \\ & & & Z_\mathrm{orig} & & & \vdots & & \vdots & & \vdots \\ & & & & & & Z_{lk} & \dotsm & Z_{lp} & \dotsm & Z_{lk} - Z_{lp} \\ & & & & & & \vdots & & \vdots & & \vdots \\ k & Z_{k1} & \dotsm & \dotsm & Z_{km} & \dotsm & Z_{kk} & \dotsm & Z_{kp} & \dotsm & Z_{kk} - Z_{kp} \\ & \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\ p & Z_{p1} & \dotsm & \dotsm & Z_{pm} & \dotsm & Z_{pk} & \dotsm & Z_{pp} & \dotsm & Z_{pk} - Z_{pp} \\ & \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\ & \vdots & & & \vdots & & \vdots & & \vdots & & \vdots \\[.5ex] \cmidrule(lr){2-11} q & \rule[-1ex]{0ex}{3.7ex} Z_{k1} - Z_{p1} & \dotsm & \dotsm & Z_{km} - Z_{pm} & \dotsm & Z_{kk} - Z_{pk} & \dotsm & Z_{kp} - Z_{pp} & \dotsm & Z_{th, kp} + Z_{b}\\ \end{block} \end{blockarray}$$
\end{minipage}}\vspace{1ex}
\blindtext% for testing purpose only
\end{document}