3
\documentclass[12pt,reqno]{amsart} \usepackage{amsmath,amssymb,amsthm} \begin{document} $$ A= \left[\begin{array}{ccccccc} 0\\ & 1\\ && 0\\ &&&\frac{1}{2!}\\&&&&0\\&&&&&\frac{1}{3!}\\&&&&&&\ddots\end{array}\right],\;\, T = \left[\begin{matrix}0 & 1 \\ &0 & 1 \\ &&\ddots&\ddots\end{matrix}\right]. $$ \end{document} 

I want to be more precise in writing these two matrices

enter image description here

5
  • 4
    have a look nicematrix package Commented Jan 5 at 8:17
  • 2
    tex.stackexchange.com/q/503/319072 Commented Jan 5 at 8:43
  • Are those lines parts of the matrix or is it only indication 0s will take the whole upper/lower triangles? Commented Jan 5 at 13:21
  • Only indicate 0 Commented Jan 5 at 13:23
  • Just a suggestion - would writing $\operatorname{diag}\left(0, 1, 0, \frac{1}{2!}, 0, \frac{1}{3}, \ddots\right)$ instead of the full matrix form work? Commented Jan 5 at 19:30

4 Answers 4

11

Here's a solution using the matrix library of tikz for the drawing:

enter image description here

Here's the code:

\documentclass[12pt, reqno]{amsart} \usepackage{amsmath,amssymb,amsthm} \usepackage{tikz} % <-- For drawing stuff \usetikzlibrary{matrix, positioning} % <-- For matrix notation and relative positioning \begin{document} \begin{tikzpicture}[ every left delimiter/.style={xshift=0.25cm}, every right delimiter/.style={xshift=-0.15cm} ] \matrix[matrix of math nodes, nodes in empty cells, left delimiter={[ }, right delimiter = { ] }] (matrix) { 0 & & & & & & \\[-0.1cm] & 1 & & & & & \\[-0.1cm] & & 0 & & & & \\[-0.1cm] & & & \frac{1}{2!} & & & \\[-0.1cm] & & & & 0 & & & \\[-0.1cm] & & & & & \frac{1}{3!} & \\[-0.1cm] & & & & & & \ddots \\[-0.1cm] }; \draw[red] ([yshift=0.35cm]matrix-2-1.north west) -- ([xshift=0.05cm]matrix-7-7.260) -- (matrix-7-1.south west) -- cycle node at ([xshift=0.25cm]matrix-5-2)[font=\huge] {0} ; % Lower triangle \draw[red] ([yshift=0.25cm, xshift=-0.25cm]matrix-1-2.north west) -- ([yshift=0.25cm, xshift=0.5cm]matrix-1-7.north east) -- ([xshift=0.25cm, yshift=0.1cm]matrix-7-7.south east) -- cycle node[font=\huge] at (matrix-3-6){0}; % Upper triangle \node[left = 0.25cm of matrix] {\(A = \)}; % text next to matrix % Onto the 2nd matrix now \node[right = 0.0cm of matrix] (mtext) {\(, \ T =\)}; \matrix[matrix of math nodes, nodes in empty cells, left delimiter={[ }, right delimiter = { ] }, right = 0.0cm of mtext] (matrix2) { 0 & 1 & & \\[-0.1cm] & 0 & 1 & \\[-0.1cm] & & \ddots & \ddots \\[-0.1cm] }; \draw[red] ([yshift=0.1cm, xshift=-0.15cm]matrix2-1-1.south) -- ([xshift=0.5cm]matrix2-3-2.south east) -- (matrix2-3-1.south west) -- cycle node[font=\large] at ([yshift=-0.25cm, xshift=0.15cm]matrix2-2-1) {0}; % Lower triangle \draw[red] ([yshift=0.2cm, xshift=-0.25cm]matrix2-1-3.north west) -- ([yshift=0.2cm, xshift=0.25cm]matrix2-1-4.north east) -- ([yshift=-0.25cm]matrix2-3-4.east) -- cycle node[font=\large] at ([yshift=0.25cm, xshift=-0.1cm]matrix2-2-4){0}; % Upper triangle \end{tikzpicture} \end{document} 

As you can tell from the code, building the matrix in tikz allows for very precise control and drawing. You could change/shift every little detail of my drawing to your personal liking. The finetuning potential seems to be endless. It's a worthwhile investment to learn to make matrices with tikz if your matrices involve heavy usage of drawings. Alternatively, the nicematrix package can be used to achieve something similar since it uses tikz under the hood, but I don't know if you can finetune it as much.

2
  • thanks @Atex. But I don't like them in red. I will write these matrices in my paper and I want to be more clear Commented Jan 5 at 12:09
  • 6
    The nice advantage of connecting everything through tikz is that you can quite simply change aspects of the drawing, too. If you don't like the current coloring, you could change the draw[red] option from red to black or whatever color you'd like to have instead:) Commented Jan 5 at 12:29
9

A simple solution without additional packages: We first define a "big zero" with null dimensions so that it does not mess up the line spacing, and then place it in an appropriate location in the array.

\documentclass[12pt,reqno]{amsart} \newcommand{\bigo}{\makebox(0,0){\text{\huge 0}}} \begin{document} $$ A= \left[\begin{array}{ccccccc} 0 & & & & & & \\ & 1 & & & & \bigo & \\ & & 0 & & & & \\ & & & \frac{1}{2!} & & & \\ & & & & 0 & & \\ & \bigo & & & &\frac{1}{3!} &\\ & & & & & & \ddots \end{array}\right],\;\, %% T = \left[\begin{matrix} 0 & 1 & &\raisebox{-0.7ex}[0ex][0ex]{\hspace{-2ex}\bigo} \\ & 0 & 1 &\\ \raisebox{2ex}[0ex][0ex]{\hspace{1ex}\bigo} & & \ddots & \ddots \end{matrix}\right]. $$ \end{document} 

Since the second matrix is rather small, there is not much space to add a big zero, so manually adjusting the vertical positioning by \raisebox gives better results. You may actually consider making the matrix larger by repeating a few more diagonal elements.

enter image description here

3
  • +1. Always nice to see simple and effective solutions without the need for additional packages! Commented Jan 5 at 16:35
  • Thank you. What about $T$? Commented Jan 5 at 18:06
  • @Student I edited the answer to include T. Commented Jan 5 at 18:54
8

Here's another way to create diagonal matrix with single 0's at upper and lower triangles. The solution below requires a bit of knowledge of nicematrix and tikz:

The code:

\documentclass{article} \usepackage{tikz} \usepackage{nicematrix} \tikzset{ every node/.style = { inner xsep=0pt, inner ysep=0pt, execute at begin node=\(, execute at end node=\), }, every path/.style = { rounded corners=6pt, }, } \begin{document} \begin{gather} A = \begin{bNiceMatrix} 0 & & & & & & \NotEmpty \\ & 1 & & & & & \\ & & 0 & & & & \\ & & & \frac{1}{2!} & & & \\ & & & & 0 & & \\ & & & & & \frac{1}{3!} & \\ \NotEmpty & & & & & & \ddots \CodeAfter \begin{tikzpicture} \node[ anchor=south west, scale=2.5, ] at (last-1) {0}; \node[ anchor=north east, scale=2.5, ] at (1-last) {0}; \end{tikzpicture} \end{bNiceMatrix} \\[6pt] T = \begin{bNiceMatrix} 0 & 1 & & \NotEmpty \\ & 0 & 1 & \\ \NotEmpty & & \ddots & \ddots \CodeAfter \begin{tikzpicture} \node[ anchor=south west, scale=1.75, xshift=-1pt, ] at (last-1) {0}; \node[ anchor=north east, scale=1.75, yshift=3pt, xshift=2pt, ] at (1-last) {0}; \end{tikzpicture} \end{bNiceMatrix} \end{gather} \end{document} 

enter image description here

EDIT.
The following code will typeset two equations in one line including equation numbers

% ... \begin{equation} A = \begin{bNiceMatrix} % ... the same content \end{bNiceMatrix}, \qquad T = \begin{bNiceMatrix} % ... the same content \end{bNiceMatrix} \end{equation} % ... 

A starred version of equation environment, that is equation*, typesets everything the same, with one exception that eq. number is not included. It's worth mentioning the shorter notation \[...\] can also be used, which is equivalent of equation* env.

The \quad and \qquad add some space between equations. Otherwise, they would stick together. More precisely, a macro \hspace{<length unit>} will add a specific space, e.g. 1cm, 1mm, 3pt, etc. \quad and \qquad are equivalent of \hspace{1em} and \hspace{2em}, respectively.

5
  • thanks @Celdor. Can I write then in the same equation? Thanks Commented Jan 5 at 13:46
  • @Student Np. See my edit. You just need to change the environment and remove \\[6pt] or change it to some extra space s.a. \quad, so that equations do not stick together. I would also recommend to have a look at amsmath package to have an idea about the correct math environment in certain situations. mathtools is another useful package. It is built on amsmath, adds some improvements, and automatically loads amsmath if it's included in code--there is no need to load both. Commented Jan 5 at 14:52
  • thanks but copied in my document and it does not complile. May be since I have already \usepackage{tikz-cd} Commented Jan 5 at 15:44
  • in my document I have already these codes %-----pour faire diagramm------------- \usepackage{tikz-cd} \usetikzlibrary{overlay-beamer-styles} %--------------------------- \usepackage{pifont} %bouni \usepackage{tabularx} %%%%%%%%%%%%bclogo%%%%%%%%%%% \usepackage{soul} \setul{}{1.5pt} \usepackage[tikz]{bclogo} \colorlet{bctitle}{Maroon} \renewcommand\bcStyleTitre[1]{\vskip-0.8em\bfseries\color{bctitle}\ul{#1}\vskip-0.7em} Commented Jan 5 at 15:49
  • They should not collide. What exactly is the error? Packages like tikz-cd load tikz in background so you don't need to load tikz explicitly. Try to remove \usepackage{tikz} or change \usepackage{tikz-cd} to \usetikzlibrary{cd} (tikz-cd package doc.) If you use beamer, read tikz-cd page 14. There is reported a workaround to some common problem when both beamer and tikz-cd are used. Commented Jan 5 at 16:24
3

With nicematrix.

\documentclass{article} \usepackage{nicematrix} \begin{document} $A = \begin{bNiceMatrix} 0 \\ & 1 & & & & \Block{2-2}<\Huge>{0} \\ & & 0 \\ & & & \frac{1}{2!} \\ & & & & 0 \\ & \Block{2-2}<\Huge>{0} & & & & \frac{1}{3!} \\ & & & & & & \ddots \end{bNiceMatrix}$, $T = \begin{bNiceMatrix} 0 & 1 & \Block[r]{2-2}<\Huge>{0} \\ \Block[l,b]{2-2}<\Huge>{0} & 0 & 1 \\ & & \ddots & \ddots \\ \end{bNiceMatrix} $ \end{document} 

Output of the above code

1
  • I would say the best solution, no messing with tikz (my answer), clear and compact code, and things are just put in place in code :) Commented Jan 6 at 10:49

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.