如何在 LaTeX 中圈出矩阵的部分?

如何在 LaTeX 中圈出矩阵的部分?

我目前正在写一份实验报告,其中我必须解释矩阵的高斯消元法。作为解释的一部分,我想将矩阵的某些部分画成圆圈/椭圆。

有没有办法将矩阵的主对角线或角画成圆圈?下面的图片带有示例。我想我可能必须\put在数组/矩阵环境之上使用结构,但我不知道该怎么做。

编辑:这是我目前必须生成的图片中所绘制的矩阵:

\usepackage[utf8]{inputenc}
\usepackage{indentfirst}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage[numbers]{natbib}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\usepackage{layout}
\usepackage[title]{appendix}
\usepackage[justification=centering]{caption}
\usepackage{titlesec}
\usepackage[percent]{overpic}
\usepackage{amsmath}
\usepackage{systeme}
\usepackage{blkarray, bigstrut}

...

\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             1 & -1 &  3 & -3 \\
            -1 &  0 & -2 &  1 \\
             2 &  2 &  4 &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}

绕主对角线

把左下角画圈

圈出右上角

答案1

这是一种可能的使用方法tikzmark

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blkarray, bigstrut}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,fit}
\begin{document}
\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             \tikzmarknode{A11}{1} & -1 &  3 & -3 \\
            -1 &  0 & -2 &  1 \\
             2 &  2 &  \tikzmarknode{A33}{4} &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
 \draw let \p1=($(A33)-(A11)$),\n1={atan2(\y1,\x1)} in 
 node[rotate fit=\n1,fit=(A11) (A33),draw,rounded corners,inner sep=2pt]{};
\end{tikzpicture}

\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             1 & -1 &  3 & -3 \\
            \tikzmarknode{B21}{-1} &  0 & -2 &  1 \\
             \tikzmarknode{B31}{2} &  \tikzmarknode{B32}{2} &  4 &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
\node[fit=(B21) (B31) (B32),inner sep=2pt] (FB){};
\path (FB.south east) arc(-90:45:4pt) coordinate(aux1);
\draw (aux1) arc(45:-90:4pt) -- ([xshift=4pt]FB.south west)
arc(-90:-180:4pt) -- (FB.north west) arc(180:45:4pt) -- cycle;
\end{tikzpicture}

\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             1 & \tikzmarknode{C12}{-1} &  \tikzmarknode{C13}{3} & -3 \\
             -1 &  0 & \tikzmarknode{C23}{-2} &  1 \\
             2 &  2 &  4 &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
\node[fit=(C12) (C23) (C13),inner sep=2pt] (FC){};
\path (FC.north west) arc(90:225:4pt) coordinate(aux2);
\draw (aux2) arc(225:90:4pt) -- ([xshift=-4pt]FC.north east)
arc(90:0:4pt) -- (FC.south east) arc(0:-135:4pt) -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

更短的解决方案如下

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blkarray, bigstrut}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             \tikzmarknode{A11}{1} & -1 &  3 & -3 \\
            -1 &  0 & -2 &  1 \\
             2 &  2 &  \tikzmarknode{A33}{4} &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
 \draw[red] plot[smooth cycle] coordinates {(A11.north)
 (A33.north east) (A33.south)  (A11.south west)};
\end{tikzpicture}

\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             1 & -1 &  3 & -3 \\
            \tikzmarknode{B21}{-1} &  0 & -2 &  1 \\
             \tikzmarknode{B31}{2} &  \tikzmarknode{B32}{2} &  4 &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
\draw[red] plot[smooth cycle] coordinates {(B21.north west) (B21.north east)
 (B32.north east) (B32.south east) (B31.south west)};
\end{tikzpicture}

\begin{center}
    \begin{blockarray}{cccc}
        \begin{block}{ [ ccc| c ]}
            \bigstrut[t]
             1 & \tikzmarknode{C12}{-1} &  \tikzmarknode{C13}{3} & -3 \\
             -1 &  0 & \tikzmarknode{C23}{-2} &  1 \\
             2 &  2 &  4 &  0 \bigstrut[b] \\
        \end{block}
    \end{blockarray}
\end{center}
\begin{tikzpicture}[remember picture,overlay]
\draw[red] plot[smooth cycle] coordinates {(C12.north west) (C13.north east)
 (C23.south east) (C23.south west) (C12.south west)};
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果将全部替换\tikzmarknode\tikzmarknode[inner sep=1pt]

在此处输入图片描述

相关内容