4

I have tried repeatedly to google for the solution to this problem. I have a matrix that looks like this. enter image description here

But I want it to look like this. enter image description here

Notice how the B, C, D and E are "very tightly centered" around the A. Here is my code.

\documentclass[12pt,a4paper]{article} \usepackage{amsmath} \begin{document} \newcommand{\matt}[5] { $ \begin{bmatrix} \begin{array}{ c c c } \begin{bmatrix} 2+r & -1 \\ -1 & 2+r & -1 \\ & \ddots & \ddots & \ddots \\ & & \ddots & \ddots & \ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{bmatrix} & {#3} & \\ {#4} & {#1} & {#2} \\ & {#5} & \begin{bmatrix} 2+r & -1 \\ -1 & 2+r & -1 \\ & \ddots & \ddots & \ddots \\ & & \ddots & \ddots & \ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{bmatrix} \\ \end{array} \end{bmatrix} $ } \matt {A} {B} {C} {D} {E} \end{document} 

Any thoughts?

Thanks, Bob.

2
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Nice question indeed! However, (with my mathematics typesetter hat on) I don't think you hould do that if $C$, $D$, $B$ and $F$ are matrices or vectors and not numbers. Commented Apr 6, 2015 at 21:30
  • Ah .. but for my need, they are just C, D, etc. Sometimes I need Z_n or Z_{n+1} .. but that's it. Commented Apr 6, 2015 at 21:38

2 Answers 2

3

Use adjustbox to get the right vertical alignment:

\documentclass[12pt,a4paper]{article} \usepackage{amsmath,adjustbox} \newenvironment{Pbmatrix}[1][c] {\begin{adjustbox}{valign=#1}$\begin{bmatrix}} {\end{bmatrix}$\end{adjustbox}} \newcommand{\matt}[5]{ \begin{bmatrix} \begin{Pbmatrix}[b] 2+r & -1 \\ -1 & 2+r & -1 \\ & \ddots & \ddots & \ddots \\ & & \ddots & \ddots & \ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{Pbmatrix} & #3 \\ \hfill #4 & #1 & #2\hfill \\ & #5 & \begin{Pbmatrix}[t] 2+r & -1 \\ -1 & 2+r & -1 \\ & \ddots & \ddots & \ddots \\ & & \ddots & \ddots & \ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{Pbmatrix} \end{bmatrix} } \begin{document} \[ \matt {A} {B} {C} {D} {E} \] \end{document} 

The auxiliary Pbmatrix environment has an alignment optional argument to get top or bottom alignment.

enter image description here

2
  • Could you show me how to resize the entire matrix so that it is 90% of its size? It is now too wide for my page. Commented Apr 7, 2015 at 1:11
  • @BobZigon You can always do \scalebox{.9}{$\matt{A}{B}{C}{D}{E}$} (with the graphicx package), but I probably would give a symbolic name to the matrix in the corners. Commented Apr 7, 2015 at 9:49
1

For information, here is what you can do with nicematrix.

\documentclass[12pt,a4paper]{article} \usepackage{nicematrix} \begin{document} \begin{equation*} \setlength{\arraycolsep}{4pt} \left[\begin{array}{@{}rcl@{}} \begin{bNiceMatrix}[b] 2+r & -1 \\ -1 & 2+r & -1 \\ & \Ddots & \Ddots & \Ddots \\ & & \Ddots & \Ddots & \Ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{bNiceMatrix} & C \\ D & A & B \\ & E & \begin{bNiceMatrix}[t] 2+r & -1 \\ -1 & 2+r & -1 \\ & \Ddots & \Ddots & \Ddots \\ & & \Ddots & \Ddots & \Ddots \\ & & & -1 & 2+r & -1 \\ & & & & -1 & 2+r \\ \end{bNiceMatrix} \end{array}\right] \end{equation*} \end{document} 

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

Output of the above code

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.