
\documentclass{beamer}
\usetheme{Madrid}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{frame}{Matrix}
This is an example of a matrix.
\begin{tikzpicture}
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),ampersand replacement=\&] (m)
{
8 \& 8 \& 1 \& 6 \\
3 \& 8 \& 5 \& 7 \\
4 \& 8 \& 9 \& 5 \\
};
\draw[color=red, thick] (m-1-1.north west) -- (m-1-3.north east) -- (m-2-3.south east) -- (m-2-1.south west) -- (m-1-1.north west);
\draw[color=blue, thick] (m-2-1.north west) -- (m-2-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-2-1.north west);
\end{tikzpicture}
\end{frame}
\end{document}
저는 (Beamer에서) 매트릭스에 두 개의 상자를 그렸습니다. 두 상자가 부분적으로 겹쳐서 파란색 상자가 부분적으로 빨간색 상자 위에 놓이는 점을 제외하면 작동합니다. 이는 그리 좋지 않습니다.
파란색 상자를 더 크게 또는 더 작게 만들어 겹치지 않도록 할 수 있는 방법이 있습니까? (겹침을 피하는 다른 방법도 환영합니다.)
답변1
다음과 같은 결과를 기대한다고 가정해 보겠습니다.
\documentclass{beamer}
\usetheme{Madrid}
\usepackage{amsmath,tikz}
\usetikzlibrary{fit,matrix}
\tikzset{
mN/.style = {%myNode
draw=#1, thick, inner sep=0pt}
}
\begin{document}
\begin{frame}{Matrix}
This is an example of a matrix.
\begin{tikzpicture}
\matrix [matrix of math nodes, column sep=1pt,
left delimiter=(,right delimiter=),ampersand replacement=\&] (m)
{
8 \& 8 \& 1 \& 6 \\
3 \& 8 \& 5 \& 7 \\
4 \& 8 \& 9 \& 5 \\
};
\node[mN=red, xshift= 2pt, fit=(m-1-1) (m-2-3)] {};
\node[mN=blue,xshift=-2pt, fit=(m-2-1) (m-3-3)] {};
\end{tikzpicture}
\end{frame}
\end{document}
편집하다:코드를 약간 최적화했습니다.