I am trying to demonstrate in a Latex document how to invert a matrix, but with the bmatrix
and vmatrix
commands I am unable to draw this array:
How can I represent this matrix in Latex?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHere you are:
\documentclass{article}
\usepackage{mathtools} %
\begin{document}
\[ \renewcommand{\arraystretch}{1.4}
\begin{bmatrix}
s + 3 & 1 & 0 & \vrule & 1 & 0 & 0 \\
-2 & s & 0 & \vrule & 0 & 1 & 0 \\
1 & 0 & a & \vrule & 0 & 0 & 1
\end{bmatrix}
\]
\end{document}
Edit : Another possibility, with blkarray
and bigstrut
:
\[
\setlength{\BAextrarowheight}{3pt}
\setlength{\bigstrutjot}{1ex}
\begin{blockarray}{[ccc|ccc]}
s + 3 & 1 & 0 & 1 & 0 & 0 \bigstrut[t]\\
-2 & s & 0 & 0 & 1 & 0 \\
1 & 0 & a & 0 & 0 & 1 \bigstrut[b]
\end{blockarray}
\]
With array
for the alignment and the vertical line and \left[
and \right]
for the surronding brackets:
\documentclass{article}
\begin{document}
\[
\left[
\begin{array}{ccc|ccc}
s+3 & 1 & 0 & 1 & 0 & 0 \\
-2 & s & 0 & 0 & 1 & 0 \\
1 & 0 & s & 1 & 0 & 1 \\
\end{array}
\right]
\]
\end{document}
EDIT: 2020-7-18 Here there is my proposal using nicematrix
package. I remember the comment of @F. Pantigny that since version 5.0 it is necessary to use c
instead of C
.
\documentclass[a4paper,12pt]{article}
\usepackage{nicematrix}
\begin{document}
$\begin{bNiceArray}{ccc|ccc}
s+3 & 1 & 0 & 1 & 0 & 0 \\
-2 & s & 0 & 0 & 1 & 0 \\
1 & 0 & s & 1 & 0 & 1
\end{bNiceArray}$
\end{document}
Just for fun with TikZ
and the matrix
library.
\documentclass[12pt,tikz,border=5mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every left delimiter/.style={xshift=1ex},
every right delimiter/.style={xshift=-1ex}]
\matrix (ma matrice)[matrix of math nodes,
left delimiter={[},
right delimiter={]}
]
{
s+3 & 1 & 0 & 1 & 0 & 0 \\
-2 & s & 0 & 0 & 1 & 0 \\
1 & 0 & s & 1 & 0 & 1 \\
};
\draw[thick,red] (ma matrice-1-3.north east) -- (ma matrice-3-3.south east);
\end{tikzpicture}
\end{document}
I add another solution using spalign
package:
\documentclass[a4paper,12pt]{article}
\usepackage{spalign}
\begin{document}
\[\spaligndelims{[}{]}
\spalignaugmathalf[c]{s+3 1 0 1 0 0; -2 s 0 0 1 0; 1 0 s 1 0 1}
\]
\end{document}