# Matrices with same height

I want to write a matrix equation and my current code is following:

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}

\begin{document}
$$\begin{pmatrix} 1 & 0 & 0 & \cdots & \cdots & 0 \\ \mu & \lambda & \nu & \ddots & & \vdots \\ 0 & \mu & \lambda & \nu & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & 0 & \mu & \lambda & \nu \\ 0 & \cdots & \cdots & 0 & -1/h & 1/h \\ \end{pmatrix} \cdot \begin{pmatrix} T^{(j+1)}(0) \\ T^{(j+1)}(h) \\ \vdots \\ \vdots \\ \vdots \\ T^{(j+1)}(N\cdot h) \end{pmatrix} = \begin{pmatrix} T(0) \\ f(h) \\ f(2h) \\ \vdots \\ f((N-1)\cdot h) \\ blabla \end{pmatrix}$$

\end{document}


however, the resulting matrices have slightly different heights. How do I set them to be the same? Result is in the attached picture:

• Can you wrap your code into a minimal compilable document? It makes it easier for people to play with it, and shows which packages are needed to create the fragment you posted. Jan 18, 2016 at 0:20

I think the easiest solution, i.e., the one that requires the least amount of additional typing, involves increasing the value of \arraystretch. Its default value is 1.0; increasing it to about 1.8 at the start of the equation environment should do the job.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\label{eq:xyz} \renewcommand\arraystretch{1.8} % default value: 1.0 \begin{pmatrix} 1 & 0 & 0 & \cdots & \cdots & 0 \\ \mu & \lambda & \nu & \ddots & & \vdots \\ 0 & \mu & \lambda & \nu & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & 0 & \mu & \lambda & \nu \\ 0 & \cdots & \cdots & 0 & -1/h & 1/h \\ \end{pmatrix} \cdot \begin{pmatrix} T^{(j+1)}(0) \\ T^{(j+1)}(h) \\ \vdots \\ \vdots \\ \vdots \\ T^{(j+1)}(N h) \end{pmatrix} = \begin{pmatrix} T(0) \\ f(h) \\ f(2h) \\ \vdots \\ f((N-1) h) \\ \text{blabla} \end{pmatrix}$$
\end{document}


For consistency reasons, I don't think that increasing the \arraystretch is a good idea. However, if we correctly understand the cause of this behavior, we may come with a simple and exact solution. The main cause of this problem here is writing symbols of different heights in the three matrices, namely, the \vdots and \ddots symbols which are higher than the rest of the symbols.

To remedy this, one should deliberately introduce redundant \vdots (or \ddots) so that the three matrices can have the same number of them. The second matrix requires only one because it has only three \vdots while the first one has four of them. Similarly, the third matrix requires three \vdots since it has only one \vdots.

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\begin{document}

\newcommand{\D}{\vphantom{\vdots}}

$$\begin{pmatrix} 1 & 0 & 0 & \cdots & \cdots & 0 \\ \mu & \lambda & \nu & \ddots & & \vdots \\ 0 & \mu & \lambda & \nu & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & 0 & \mu & \lambda & \nu \\ 0 & \cdots & \cdots & 0 & -1/h & 1/h \\ \end{pmatrix} \cdot \begin{pmatrix} T^{(j+1)}(0) \\ T^{(j+1)}(h)\D \\ \vdots \\ \vdots \\ \vdots \\ T^{(j+1)}(N\cdot h) \end{pmatrix} = \begin{pmatrix} T(0) \D \\ f(h) \D \\ f(2h)\D \\ \vdots \\ f((N-1)\cdot h) \\ blabla \end{pmatrix}$$

\end{document}


Edit: (In response to the OP's comment)

If you don't like typing that \D command in every row, try this automatic alternative:

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath, array}
\newcolumntype{V}{>{\vphantom{\vdots}\arraybackslash}c}
\begin{document}

$$\left ( \begin{array}{@{}*5{c}V@{}} 1 & 0 & 0 & \cdots & \cdots & 0 \\ \mu & \lambda & \nu & \ddots & & \vdots \\ 0 & \mu & \lambda & \nu & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & 0 & \mu & \lambda & \nu \\ 0 & \cdots & \cdots & 0 & -1/h & 1/h \\ \end{array}\right ) \cdot \left ( \begin{array}{@{}V@{}} T^{(j+1)}(0) \\ T^{(j+1)}(h) \\ \vdots \\ \vdots \\ \vdots \\ T^{(j+1)}(N h) \end{array}\right ) =\left ( \begin{array}{@{}V@{}} T(0) \\ f(h) \\ f(2h) \\ \vdots \\ f((N-1) h) \\ blabla \end{array}\right )$$

\end{document}


which gives the first equation below.

Now compare equation 1 (for my code above) and equation 2 (using the \arraystretch method). Which one do you think is better? And look how they are inconsistent. Imagine that you have two consecutive paragraphs one is single-spaced and the other is almost double-spaced (except for captions, etc.). Of course they will look bad.

Besides, changing the \arraystretch requires trial and error. How would we know in advance that this 1.8 will be just the right value? Why not 1.5, for example?

• Please elaborate a bit on the "consistency reasons" that would speak against resetting \arraystretch. For sure, in my answer the scope of the redefinition of \arraystretch is local to a particular equation environment; I can't tell what potential inconsistencies might follow from such an approach.
– Mico
Jan 18, 2016 at 2:10
• honestly I think that Mico's solution is much more straightforward and works for me really well. I actually don't see why this should be more consistent. this will result in rows 1-4 being taller that 5,6. if I wanted all rows to have the same height I would have to add \D to every row, which actually isn't much that different from using \arraystretch and seems as a bit more tedious task Jan 19, 2016 at 0:34
• @Tom83B - Please see my edit for explanation. Jan 19, 2016 at 3:36
• I think it would be helpful if you made clear(er) the connection you make between some equation "looking better" and it being "more consistent". Relatedly, what is inconsistent about the \renewcommand{\arraystretch}1.8 method? Presumably, it's not the fact that the resulting rows all have the same height, right?
– Mico
Jan 19, 2016 at 4:43

Here, I just turn all pmatrix environments into \parenMatrixstacks and \parenVectorstacks. The inter-column gap in the matrix is governed by \setstacktabbedgap{} and the inter-row baselineskip is governed by \setstackgap{L}{}. This answer requires my tabstackengine package.

\documentclass[12pt,a4paper]{report}
\usepackage{amsmath,tabstackengine}
\setstacktabbedgap{1ex}
\setstackgap{L}{1.2\baselineskip}
\begin{document}
$$\parenMatrixstack{ 1 & 0 & 0 & \cdots & \cdots & 0 \\ \mu & \lambda & \nu & \ddots & & \vdots \\ 0 & \mu & \lambda & \nu & \ddots & \vdots \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & 0 & \mu & \lambda & \nu \\ 0 & \cdots & \cdots & 0 & -1/h & 1/h } \cdot \parenVectorstack{ T^{(j+1)}(0) \\ T^{(j+1)}(h) \\ \vdots \\ \vdots \\ \vdots \\ T^{(j+1)}(N\cdot h) } = \parenVectorstack{ T(0) \\ f(h) \\ f(2h) \\ \vdots \\ f((N-1)\cdot h) \\ blabla }$$

\end{document}