# In array environment, why does \multirow stretch rows too much when using = for width entry?

When = is used, the content of \multirow command is adjusted to automatically be equal to the column in which \multirow appears. But this does not seem to be the case with me. I am trying to use array environment to build detailed matrices with columns and rows separators for illustration purposes. I get the following output

I got the output by adjusting the width of \multirow manually. If I adjust it to be =, the output stretches beyond margins

My source code

\documentclass[11pt, a4paper]{book}

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

\usepackage{makecell}
\usepackage{multirow}

\newlength{\arraycolsepdefaultl}
\setlength{\arraycolsepdefaultl}{2.12mm}
\newcommand{\arraycolsepdefault}{ \setlength{\arraycolsep}{\arraycolsepdefaultl} }
\arraycolsepdefault

\newcommand {\arraystretchdefaultl} {1.3}
\arraystretchdefault

\usepackage{bm}

\begin{document}

$$\setlength{\arraycolsep}{1.06mm} \left[ \begin{array}{c} V_{1} \\ \vdots \\ V_{k} \\ \vdots \\ V_{p} \\ \vdots \\ \Xhline{0.25mm} 0 \end{array} \right] % = % \renewcommand{\arraystretch}{1.7} \left[ \begin{array}{c >{\medspace}c !{\vrule width 0.25mm}>{\medspace}c} \multirow{5}{=}{\centering \LARGE \bm{Z}_{orig}} & & \multirow{5}{=}{\centering col. \thinspace k - col. \thinspace p} \\ & & \\ & & \\ & & \\ & & \\ \Xhline{0.25mm} row. \thinspace k - row. \thinspace p & & Z_{th, \thinspace kp} + Z_{b} \end{array} \right] \arraystretchdefault \left[ \begin{array}{c} I_{1} \\ \vdots \\ I_{k} \\ \vdots \\ I_{p} \\ \vdots \\ \Xhline{0.25mm} I_{q} \end{array} \right] \arraycolsepdefault$$

\end{document}

• You are changing \arraystretch in the middle of your set of array constructions, and that affects how the number of rows for \multirow{<rows>} is interpreted. Why do you need to change it? – Werner Jul 20 '18 at 23:57
• No, I am changing it before array environment is initiated. I change the array stretch so that elements are vertically separated and become more readable. – Al-Motasem Aldaoudeyeh Jul 20 '18 at 23:59

The following example avoids multirow but instead uses \vphantoms to ensure that the matrix constructs match each other (vertically). The centred element is raise 1/2 a baseline to put it in the middle of the line (since there are an even number of rows above the \Xhline).

\documentclass{article}

\usepackage{bm,makecell,amsmath}

\begin{document}

$\renewcommand{\arraystretch}{1.3} \left[\begin{array}{ c } V_1 \\ \vdots \\ V_k \\ \vdots \\ V_p \\ \vdots \\ \Xhline{0.25mm} 0 \end{array}\right] = \left[\begin{array}{ c !{\vrule width 0.25mm} c } \vphantom{V_1} & \\ \vphantom{\vdots} & \\ \vphantom{V_k} & \\ \vphantom{\vdots}\raisebox{.5\normalbaselineskip}[0pt][0pt]{\bm{Z}_{\text{orig}}} & \raisebox{.5\normalbaselineskip}[0pt][0pt]{\text{col.\ k - col.\ p}} \\ \vphantom{V_p} & \\ \vphantom{\vdots} \\ \Xhline{0.25mm} \text{row.\ k - row.\ p} & Z_{\text{th, kp}} + Z_b \end{array}\right] \left[\begin{array}{ c } I_1 \\ \vdots \\ I_k \\ \vdots \\ I_p \\ \vdots \\ \Xhline{0.25mm} I_q \end{array}\right]$

\end{document}

• That is a desired result since the column widths are determined automatically depending on the contents. The use of \vphantom over and over again seems to be redundant. I wonder if someone can create a package to automatically force brackets surrounding array environment equal – Al-Motasem Aldaoudeyeh Jul 21 '18 at 2:09
• You can use bmatrix from amsmath. The horizontal spacing will have to be adjusted. – Werner Jul 21 '18 at 2:13
• will bmatrix provide the ability to customize the matrix similarly to what we get with array environment? – Al-Motasem Aldaoudeyeh Jul 21 '18 at 2:30
• bmatrix will provide the ability to bracket a matrix without the column specifications. – Werner Jul 21 '18 at 2:38
• \multirow{5}{=}{...} consider used column width
• since in your case it is not defined in advance (as at columns as are p{<width>}), it for it consider \linewidth, consequently result which you obtained
• a cure: use \multirow{5}{*}{...} instead:

\documentclass[11pt, a4paper]{book}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{makecell}
\usepackage{multirow}

\newlength{\arraycolsepdefaultl}
\setlength{\arraycolsepdefaultl}{2.12mm}
\newcommand{\arraycolsepdefault}{ \setlength{\arraycolsep}{\arraycolsepdefaultl} }
\arraycolsepdefault

\newcommand {\arraystretchdefaultl} {1.3}

\usepackage{bm}

\begin{document}
$$\setlength{\arraycolsep}{1.06mm} \arraystretchdefault \left[ \begin{array}{c} V_{1} \\ \vdots \\ V_{k} \\ \vdots \\ V_{p} \\ \vdots \\ \Xhline{0.25mm} 0\rule{0pt}{3.5ex} \end{array} \right] = \renewcommand{\arraystretch}{1.7} \left[ \begin{array}{c >{\medspace}c !{\vrule width 0.25mm}>{\medspace}c} \multirow{5}{*}{\centering \LARGE \bm{Z}_{orig}} & & \multirow{5}{*}{\text{col. } k - \text{col. } p} \\ & & \\ & & \\ & & \\ & & \\ \Xhline{0.25mm} \text{col. } k - \text{col. } p & & Z_{th,\, kp} + Z_{b} \end{array} \right] \arraystretchdefault \left[ \begin{array}{c} I_{1} \\ \vdots \\ I_{k} \\ \vdots \\ I_{p} \\ \vdots \\ \Xhline{0.25mm} I_{q}\rule{0pt}{3.5ex} \end{array} \right]$$
\end{document}


which fives:

however, approach showed in Werner answer is common in similar cases.