# How to draw a circle in a matrix like this?

I came across matrices like this in a book. Can I create this using pure latex commands or do I need to using something like Photoshop for help?

Update: I've created the equation without circle like this:

\documentclass[a4paper,12pt,hidelinks]{article}
\usepackage{mathtools}
\begin{document}
\title{Title of the doc}
\author{me}
\date{\today}
\maketitle
\section{Example}

\begin{equation*}
\begin{vmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1n} \\
& a_{22} & \cdots & a_{2n} \\
&& \ddots & \vdots \\
&&& a_{nn}
\end{vmatrix*} =
\begin{vmatrix*}[c]
a_{11} &&& \\
a_{21} & a_{22} && \\
\vdots & \vdots & \ddots & \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{vmatrix*} =
a_{11}a_{22} \dots a_{nn}
\end{equation*}

\end{document}


• Welcome to TeX.SE! You certainly do not need photoshop for this. Could you please provide us with the code for the matrices without the "circle"? – marmot Sep 12 '18 at 13:37
• OK, yes, let me do it and update the question. I just learned latex a few hours ago and this is a good chance to practice :) – Ogrish Man Sep 12 '18 at 13:39
• The solution has been written long time ago here. – Money Oriented Programmer Sep 12 '18 at 13:47

Run with xelatex

\documentclass{article}
\usepackage{amsmath}
\usepackage{pstricks}
\begin{document}
$\begin{vmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ & a_{22} & \cdots & a_{2n} \\ \psellipse[rot=45](0.5,0)(0.3,0.6) & & \ddots & \vdots \\ & & & a_{nn} \end{vmatrix} = \begin{vmatrix} a_{11} & & & \\ a_{21} & a_{22} & & \psellipse[rot=45](-0.5,0.1)(0.3,0.6) \\ \vdots & \vdots & \ddots & \\ a_{n1} & a_{n1} & \cdots & a_{nn} \end{vmatrix} = a_{11}\, a_{22}\cdots a_{nn}$
\end{document}


and the same with package tikz

$\begin{vmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ & a_{22} & \cdots & a_{2n} \\ \tikz[overlay]\draw (0.5,0) circle [x radius=3mm,y radius=6mm,rotate=45]; & & \ddots & \vdots \\ & & & a_{nn} \end{vmatrix} = \begin{vmatrix} a_{11} & & & \\ a_{21} & a_{22} & & \tikz[overlay]\draw (-0.5,0.1) circle [x radius=3mm,y radius=6mm,rotate=45]; \\ \vdots & \vdots & \ddots & \\ a_{n1} & a_{n1} & \cdots & a_{nn} \end{vmatrix} = a_{11}\, a_{22}\cdots a_{nn}$

• Why xelatex? I get the result also with "normal" latex. – campa Sep 12 '18 at 15:00
• With latex yes, but not with pdflatex. – user2478 Sep 12 '18 at 15:09

Here is a possible way to do it with tikzmark. (UPDATE: Rotation angles of the ellipses are no longer hard coded.)

\documentclass[a4paper,12pt,hidelinks]{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit,shapes.geometric,calc}
\begin{document}
\title{Title of the doc}
\author{me}
\date{\today}
\maketitle
\section{Example}

\begin{equation*}
\begin{vmatrix*}[c]
a_{11} & a_{12} & \cdots & a_{1n} \\
& a_{22} & \cdots & a_{2n} \\
\tikzmark{m1}&& \ddots & \vdots \\
&\tikzmark{m2}&& a_{nn}
\end{vmatrix*} =
\begin{vmatrix*}[c]
a_{11} &&\tikzmark{m3}& \\
a_{21} & a_{22} &&\tikzmark{m4} \\
\vdots & \vdots & \ddots & \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{vmatrix*} =
a_{11}a_{22} \dots a_{nn}
\end{equation*}
\begin{tikzpicture}[overlay,remember picture]
\path let \p1=($(pic cs:m2)-(pic cs:m1)$),\n1={atan2(\y1,\x1)} in
node[ellipse,fit=(pic cs:m1)(pic cs:m2),draw,rotate fit=\n1,inner sep=0pt,
yshift=4pt]{};
\path let \p1=($(pic cs:m4)-(pic cs:m3)$),\n1={atan2(\y1,\x1)} in
node[ellipse,fit=(pic cs:m3)(pic cs:m4),draw,rotate fit=\n1,inner sep=0pt]{};
\end{tikzpicture}
\end{document}