# Matrix writing goes wrong

I want to write down this matrix in my latex document

My code for that is

\begin{document}
$$F_x= \quad \begin{bmatrix} 1 & 0 & 0 & 0 & ... & 0 \\ 0 & 1 & 0 & 0 & ... & 0 \\ 0 & 0 & 1 & 0 & ... & 0 \\ & & & & 3N Columns \end{bmatrix}$$
\end{document}


This code not produce desired result. Where should I change to produce desire result?

• Side note: use $...$ and not $$...$$ for display math! – user496634 Sep 21 at 23:28

It's a bit more complicated. You can do it with nested matrices:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$F_x= \begin{bmatrix} \, % for symmetry \begin{matrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{matrix} & \smash{\underbrace{% \begin{matrix} 0 & \dots & 0 \\ 0 & \dots & 0 \\ 0 & \dots & 0 \end{matrix}}_{\text{3N columns}}% }\, \end{bmatrix} \vphantom{% \underbrace{% \begin{matrix} 0 & \dots & 0 \\ 0 & \dots & 0 \\ 0 & \dots & 0 \end{matrix}}_{\text{3N columns}}% }$

\end{document}


The \vphantom is needed to maintain the real size of the object, because we smash the second inner matrix in order TeX doesn't “see” the depth of the underbrace.

You can simplify the input by defining a temporary macro:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$\newcommand{\tempmatrix}{% \underbrace{% \begin{matrix} 0 & \dots & 0 \\ 0 & \dots & 0 \\ 0 & \dots & 0 \end{matrix}}_{\text{3N columns}% }% } F_x= \begin{bmatrix} \, % for symmetry \begin{matrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{matrix} & \smash{\tempmatrix} \, \end{bmatrix} \vphantom{\tempmatrix}$

\end{document}

• Frankly, I'dont see any difference using or not using the vphantom instruction. Are you this is useful, compiling with overleaf.com no difference seeable on the output pdf? – pzorba75 Sep 22 at 3:29
• @pzorba75 Add some text after the display and see. – egreg Sep 22 at 5:49

Another way to do this is as a tikz matrix of nodes:

Here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing}

\begin{document}

$$\label{E:columns} \begin{tikzpicture}[baseline=(current bounding box.center)] \matrix (M)[matrix of math nodes, left delimiter=(, right delimiter=)]{ 1 & 0 & 0 & 0 & ... & 0 \\ 0 & 1 & 0 & 0 & ... & 0 \\ 0 & 0 & 1 & 0 & ... & 0 \\ }; \draw[decorate, decoration={brace, mirror}] (M-3-4.south west)--(M-3-6.south east) node[font=\scriptsize,below left]{3N columns}; \end{tikzpicture}$$

\end{document}

• For that tikz must be install. I am using tex studio. – Saswati Sep 21 at 22:48
• @Saswati There is no problem to load tikz on TeXStudio.... – marmot Sep 22 at 3:25
• Can we add equation number? – Hafid Boukhoulda Sep 22 at 7:28
• @HafidBoukhoulda If you want an equation number then put everything inside an equation environment. I'll edit since I didn't put the label in \scriptsize. – Andrew Sep 22 at 10:05