\documentclass{standalone}
\usepackage{tikz,pgf}
\usetikzlibrary{fit,scopes,arrows,calc,shapes.misc,matrix,positioning}
\begin{document}
\newcommand{\bbrect}[3]{
\pgfmathtruncatemacro\result{#1+1};
\node[rectangle,draw,fit=(A-#1-\result.north west) (A-#1-#2.south east), inner sep = 0pt] (block#3) {}
}
\begin{tikzpicture}
\ttfamily
\begin{scope}
\matrix (A) [matrix of nodes, ampersand replacement = \&] {
{0} \& {0} \& {1} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {1} \& {1} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {0}\\
};
\end{scope}
\bbrect{1}{5}{1};
\end{tikzpicture}
\end{document}
我想\bbrect{1}{5}{1}
稍微倾斜由 创建的子矩阵矩形框架 -- 以及其所有条目0 1 0 1
。由于矩阵环境专门用于对齐项目,这似乎几乎是不可能的?
答案1
您可以倾斜框架如果将该选项添加到命令的选项rotate=<angle>
中。node
\bbrect
\documentclass{standalone}
\usepackage{tikz,pgf}
\usetikzlibrary{decorations.markings,%
snakes,fit,scopes,arrows,calc,shapes.misc,%
shapes.arrows,chains,matrix,positioning,decorations.pathmorphing,
shapes,backgrounds,decorations.text}
\begin{document}
\newcommand{\bbrect}[3]{
\pgfmathtruncatemacro\result{#1+1};
\node[rotate=-5,rectangle,draw,
fit=(A-#1-\result.north west) (A-#1-#2.south east),
inner sep = 0pt] (block#3) {}
}
\begin{tikzpicture}
\ttfamily
\begin{scope}
\matrix (A) [matrix of nodes, ampersand replacement = \&] {
{0} \& {0} \& {1} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {1} \& {1} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {0}\\
};
\end{scope}
\bbrect{1}{5}{1};
\end{tikzpicture}
\end{document}