please help me to create this in LaTeX:
5 Answers
I did not solve exactly your problem but a similar one from which you could extract useful information.
I needed to solve a determinant far more general. I used plain TikZ and the matrix function inside TiKZ. Here is the code.
\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\usepackage{pgfplots,tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[
, matrix of math nodes
, left delimiter = {(}
, right delimiter = {)}
] (m)
{
1 & \rho_1 & 0 & 0 & \cdots & 0 & 0 & \rho_{1} \\
\rho_1 & 1 & \rho_1 & 0 & \cdots & 0 & 0 & 0 \\
0 & \rho_1 & 1 & \rho_1 & \cdots & 0 & 0 & 0 \\
\vdots & & \ddots & \ddots & \ddots & & \vdots & \vdots \\
\vdots & & & \ddots & \ddots & \ddots & \vdots & \vdots \\
\vdots & & & & \rho_1 & 1 & \rho_1 & 0 \\
\vdots & & & & & \rho_1 & 1 & 0 \\
0 & \cdots & \cdots & \cdots & \cdots & 0 & \rho_1 & 0 \\
};
\coordinate (A) at (2.5,2.6);
\coordinate (B) at (-3.0,2.65);
\coordinate (C) at (2.55,-2.7);
\draw[red, dotted, line width=2] (A) circle(9pt);
\draw[red, line width=2] (B)--++(5.2,0);
\draw[red, line width=2] (C)--++(0,4.9);
\end{tikzpicture}
\end{document}
To be honest, I computed the length and positions for the segments and circles by trial and error. Sure, there should be a way to get these locations from the matrix environment in an elegant way. I do not know how to do this.
Here is the figure.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline=(#1.base)] \node (#1) {#2};}
\begin{document}
\[
\left[\begin{array}{*3{c}}
\tikzmark{left_end}{0} & 2 & \tikzmark{right_end}{1}\\
3 & -1 & 2 \\
\tikzmark{down_left}{4} & 0 & \tikzmark{down}{1}
\end{array}\right]
\]
\tikz[overlay,remember picture] {
\draw[red,thick,dashed] (left_end) circle (0.2cm);
\draw[-,red,thick] (left_end) -- ++ (1.7,0) (right_end);
\draw[-,red,thick] (left_end) -- ++ (0,-1.) (down_left);
}
\end{document}
-
-
I posted some extended comments below. If you address them in your answer, I will be happy to remove them.– user121799Feb 22, 2019 at 16:00
-
-
You can really take them over, I do not want to post an answer here. I just want to avoid that
\tikzmark
gets redefined.– user121799Feb 22, 2019 at 16:07
This is more an extended comment on the answer by Sina Ahmadi. I will be happy to remove this if in that answer a few things get changed.
\tikzmark
is a phantastic command that is part of thetikzmark
library. I would like to argue that creating a new command with this name is not a good practice.- The nodes
right_end
anddown_left
are not used. The lines are drawn as determined by the two hard-coded distances- ++ (1.7,0)
and- ++ (0,-1.)
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\[\begin{bmatrix}
\tikzmarknode[circle,draw=red,inner sep=0.5pt,densely dashed]{A11}{0} & 2 & \tikzmarknode{A13}{1}\\
3 & -1 & 2 \\
\tikzmarknode{A31}{4} & 0 & 1
\end{bmatrix}
\]
\begin{tikzpicture}[overlay,remember picture]
\draw[red] (A11.east) -- (A11.east-|A13.east)
(A11.south) -- (A11.south|-A31.south);
\end{tikzpicture}
\end{document}
-
@Said You're welcome! (BTW, you can only accept one answer. Given that you accepted Sina's answer first, you might want to place the tick there.)– user121799Feb 22, 2019 at 22:04
A simple code with pstricks
and mathtools
:
\documentclass[svgnames]{article}
\usepackage{mathtools}
\usepackage{pst-node, auto-pst-pdf}
\begin{document}
\begin{postscript}
\psset{{linecolor=DeepPink}, framesep=2pt, nodesepB=-8pt}
\[ \begin{bmatrix}
\mathclap{\circlenode[linestyle=dashed, dash=3.5pt 2.5pt]{A}{0}} & 2 & \rnode{C}{1} \\
3 & -1 & 2 \\
\rnode{B}{4} & 0 & 1
\end{bmatrix} \]
\ncline{A}{B}
\ncline{A}{C}
\end{postscript}
\end{document}
Ensure you have --enable-write18
in your LaTeX command/engine so that auto-pst-pdf
works.
It's possible to do that with nicematrix
. This package creates a PGF/Tikz node under each cell of the array. Then, it's possible to use tikz
to draw what we want.
\documentclass[svgnames]{article}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$\begin{bNiceMatrix}[margin]
0 & 2 & 1 \\
3 & -1 & 2 \\
4 & 0 & 1
\CodeAfter
\begin{tikzpicture} [color = DeepPink]
\draw [dashed] (1-1) circle (2mm) ;
\draw ([xshift=2mm]1-1.east) -- ([xshift=2mm]1-3.east) ;
\draw ([yshift=-1mm]1-1.south) -- ([yshift=-1mm]3-1.south) ;
\end{tikzpicture}
\end{bNiceMatrix}$
\end{document}