1) 如何根据第一行对齐两个矩阵 (B) 和 (C)?2) 我很喜欢这种“随机步骤”装饰。但是手册对此只字未提。有关于这种迷人装饰的提示/链接吗?
\documentclass{standalone}
\usepackage{comment}
\usepackage{tikz,pgf}
\usetikzlibrary{fit,scopes,arrows,calc,shapes.misc,shapes.arrows,chains,matrix,positioning,decorations.pathmorphing,shapes,backgrounds}
\begin{document}
\tikzset{
fuzzy/.style = {decorate, decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}},
ns/.style = {
% The shape
rectangle,
% The size
minimum size = 6mm,
rounded corners = 3mm,
% The border
very thick,
draw,
% The font
font = \ttfamily,
fuzzy
}
}
\newcommand{\bbrect}[3]{\node[rectangle,fuzzy,draw,fit=(B-#1-2.north west) (B-#2-2.south east), inner sep = 0pt] (block#3) {}}
\newcommand{\cbl}[2]{\node[rectangle,fuzzy,draw,fit=(C-#1-1.north west) (C-#1-1.south east), inner sep = 0pt] (cblock#2) {}}
\begin{tikzpicture} [
>=latex, thick,
/pgf/every decoration/.style = {/tikz/sharp corners},
fuzzy/.style = {decorate, decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}},
minimum size = 6mm, line join = round, line cap = round,
ns/.style = {rectangle, draw, fill = white, fuzzy, rounded corners = 3mm},
node distance = 6mm,
tip/.style = {->,shorten >= 1pt,fuzzy},
every join/.style = {fuzzy, rounded corners = 2mm},
hv path/.style = {to path = {-| (\tikztotarget)}},
vh path/.style = {to path = {|- (\tikztotarget)}},
skip loop/.style = {to path = {-- +(0,#1) -| (\tikztotarget)}},
BarreStyle/.style={opacity = 0.2, line width = 3 mm, rectangle},
]
\ttfamily
\begin{scope}
\matrix (B) [matrix of nodes, ampersand replacement = \&] {
\hline
{Col 1} \& {Col 2}\\
\hline
{fsdf} \& {12}\\
{xxfd} \& {7}\\
{fsdf} \& {2}\\
{} \& {2}\\
{} \& {2}\\
{} \& {2}\\
{} \& {2}\\
{} \& {2}\\
{} \& {7}\\
{} \& {7}\\
{} \& {2}\\
{} \& {2}\\
{} \& {2}\\
{} \& {8}\\
{} \& {4}\\
{} \& {4}\\
{} \& {4}\\
{} \& {4}\\
{} \& {4}\\
{} \& {4}\\
{} \& {9}\\
{} \& {11}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {1}\\
{} \& {5}\\
{} \& {5}\\
{} \& {5}\\
{} \& {6}\\
{} \& {6}\\
{} \& {6}\\
{} \& {10}\\
{} \& {3}\\
{} \& {3}\\
{} \& {3}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
{} \& {0}\\
};
\bbrect{2}{2}{1};
\bbrect{3}{3}{2};
\bbrect{4}{9}{3};
\bbrect{10}{11}{4};
\bbrect{12}{14}{5};
\bbrect{15}{15}{6};
\bbrect{16}{21}{7};
\bbrect{22}{22}{8};
\bbrect{23}{23}{9};
\bbrect{24}{32}{10};
\bbrect{33}{35}{11};
\bbrect{36}{38}{12};
\bbrect{39}{39}{13};
\bbrect{40}{42}{14};
\bbrect{43}{51}{15};
\end{scope}
\begin{scope}[xshift = 5cm]
\matrix (C) [matrix of nodes, ampersand replacement = \&] {
{12}\\
{7}\\
{2}\\
{7}\\
{2}\\
{8}\\
{4}\\
{9}\\
{11}\\
{1}\\
{5}\\
{6}\\
{10}\\
{3}\\
{0}\\
};
\cbl{1}{1};
\cbl{2}{2};
\cbl{3}{3};
\cbl{4}{4};
\cbl{5}{5};
\cbl{6}{6};
\cbl{7}{7};
\cbl{8}{8};
\cbl{9}{9};
\cbl{10}{10};
\cbl{11}{11};
\cbl{12}{12};
\cbl{13}{13};
\cbl{14}{14};
\cbl{15}{15};
\end{scope}
\begin{pgfonlayer}{background}
\foreach \i in {1,...,15} {
\path[draw,fuzzy] (block\i.north east) -- (cblock\i.north west);
\path[draw,fuzzy] (block\i.south east) -- (cblock\i.south west);
}
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
答案1
xshift=5cm
从范围中删除选项并(C)
用以下内容替换矩阵的第一行进行对齐。
\matrix (C) at ([xshift = 5cm]B-2-2.north east)[anchor=C-1-1.north west,matrix of nodes] {