我有以下矩阵:
这是从以下代码中获得的:
\usetikzlibrary{patterns}
\usetikzlibrary{matrix,decorations.pathreplacing,calc}
%opening
\title{}
\author{}
\pgfkeys{tikz/mymatrixenv/.style={decoration={brace},every left delimiter/.style={xshift=8pt},every right delimiter/.style={xshift=-8pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes,nodes in empty cells,left delimiter={[},right delimiter={]},inner sep=1pt,outer sep=1.5pt,column sep=8pt,row sep=8pt,nodes={minimum width=20pt,minimum height=10pt,anchor=center,inner sep=0pt,outer sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand*\mymatrixbraceright[4][m]{
\draw[mymatrixbrace] (#1.west|-#1-#3-1.south west) -- node[left=2pt] {#4} (#1.west|-#1-#2-1.north west);
}
\newcommand*\mymatrixbraceleft[4][m]{
\draw[mymatrixbrace] (#1.east|-#1-#2-1.north east) -- node[right=2pt] {#4} (#1.east|-#1-#2-1.south east);
}
\newcommand*\mymatrixbracetop[4][m]{
\draw[mymatrixbrace] (#1.north-|#1-1-#2.north west) -- node[above=2pt] {#4} (#1.north-|#1-1-#3.north east);
}
\newcommand*\mymatrixbracebottom[4][m]{
\draw[mymatrixbrace] (#1.south-|#1-1-#2.north east) -- node[below=2pt] {#4} (#1.south-|#1-1-#3.north west);
}
\tikzset{style green/.style={
set fill color=green!50!lime!60,draw opacity=0.4,
set border color=green!50!lime!60,fill opacity=0.1,
},
style cyan/.style={
set fill color=cyan!90!blue!60, draw opacity=0.4,
set border color=blue!70!cyan!30,fill opacity=0.1,
},
style orange/.style={
set fill color=orange!90, draw opacity=0.8,
set border color=orange!90, fill opacity=0.3,
},
style brown/.style={
set fill color=brown!70!orange!40, draw opacity=0.4,
set border color=brown, fill opacity=0.3,
},
style purple/.style={
set fill color=violet!90!pink!20, draw opacity=0.5,
set border color=violet, fill opacity=0.3,
},
kwad/.style={
above left offset={-0.1,0.23},
below right offset={0.10,-0.36},
#1
},
pion/.style={
above left offset={-0.07,0.2},
below right offset={0.07,-0.32},
#1
},
poz/.style={
above left offset={-0.03,0.18},
below right offset={0.03,-0.3},
#1
}
}
\[
% \mathbf{X} =
\begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
\matrix [mymatrix,inner sep=4pt] (m)
{
\tikzmarkin[kwad=style green]{Prime} v_{1,1} & v_{1,2} & \tikzmarkin[pion=style purple]{VL} v_{1,3} & \textcolor{white}{v_{1,4}} & & \textcolor{white}{v_{1,6}} \\
v_{2,1} & v_{2,2} & v_{2,3} & & & \\
\tikzmarkin[poz=style brown]{HL} v_{3,1} & v_{3,2} & \tikzmarkin[kwad=style orange]{Mix} v_{3,3} \tikzmarkend{Prime} &\tikzmarkin[pion=style purple]{VR} v_{3,4} \tikzmarkend{HL} & & \\
\textcolor{white}{v_{4,1}} & & \tikzmarkin[poz=style brown]{HR} v_{4,3} \tikzmarkend{VL}& \tikzmarkin[kwad=style cyan]{Bis} v_{4,4} \tikzmarkend{Mix} & v_{4,5} & v_{4,6} \tikzmarkend{HR} \\
& & & v_{5,4} & v_{5,5} & v_{5,6} \\
\textcolor{white}{v_{6,1}} & & & v_{6,4} \tikzmarkend{VR} & v_{6,5} & v_{6,6} \tikzmarkend{Bis} \\
};
% Braces
\mymatrixbraceright{1}{3}{$B'$}
\mymatrixbraceright{4}{6}{$B''$}
\mymatrixbracetop{1}{3}{$C'$}
\mymatrixbracetop{4}{6}{$C''$}
\mymatrixbracebottom{3}{3}{$F'$}
\mymatrixbracebottom{4}{4}{$F''$}
\mymatrixbraceleft{3}{3}{$E'$}
\mymatrixbraceleft{4}{4}{$E''$}
\end{tikzpicture}
\]
我试图改变:
\begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
到
\begin{tikzpicture}[scale=2,baseline={-0.5ex},mymatrixenv]
但没有效果。
当我将图片导入到另一个文档时我也尝试这样做:
\begin{figure}
\centering
\scalebox{2}{
\input{color_matrix3.tikz}
}
\end{figure}
输出确实更大,但没有居中,并且 latex 给出了很多有关数学方程的错误
答案1
首先,我提供一下代码的可编译版本。除了明显的添加内容外,我还根据上下文猜测了一些样式,但正如任何猜测一样,我的猜测可能是错误的。无论如何,这就是我得到的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns,tikzmark}
\usetikzlibrary{matrix,decorations.pathreplacing,calc}
\usepackage{hf-tikz}
%opening
\title{}
\author{}
\begin{document}
\pgfkeys{tikz/mymatrixenv/.style={decoration={brace},every left delimiter/.style={xshift=8pt},every right delimiter/.style={xshift=-8pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes,nodes in empty cells,left delimiter={[},right delimiter={]},inner sep=1pt,outer sep=1.5pt,column sep=8pt,row sep=8pt,nodes={minimum width=20pt,minimum height=10pt,anchor=center,inner sep=0pt,outer sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand*\mymatrixbraceright[4][m]{
\draw[mymatrixbrace] (#1.west|-#1-#3-1.south west) -- node[left=2pt] {#4} (#1.west|-#1-#2-1.north west);
}
\newcommand*\mymatrixbraceleft[4][m]{
\draw[mymatrixbrace] (#1.east|-#1-#2-1.north east) -- node[right=2pt] {#4} (#1.east|-#1-#2-1.south east);
}
\newcommand*\mymatrixbracetop[4][m]{
\draw[mymatrixbrace] (#1.north-|#1-1-#2.north west) -- node[above=2pt] {#4} (#1.north-|#1-1-#3.north east);
}
\newcommand*\mymatrixbracebottom[4][m]{
\draw[mymatrixbrace] (#1.south-|#1-1-#2.north east) -- node[below=2pt] {#4} (#1.south-|#1-1-#3.north west);
}
\tikzset{style green/.style={
set fill color=green!50!lime!60,draw opacity=0.4,
set border color=green!50!lime!60,fill opacity=0.1,
},
style cyan/.style={
set fill color=cyan!90!blue!60, draw opacity=0.4,
set border color=blue!70!cyan!30,fill opacity=0.1,
},
style orange/.style={
set fill color=orange!90, draw opacity=0.8,
set border color=orange!90, fill opacity=0.3,
},
style brown/.style={
set fill color=brown!70!orange!40, draw opacity=0.4,
set border color=brown, fill opacity=0.3,
},
style purple/.style={
set fill color=violet!90!pink!20, draw opacity=0.5,
set border color=violet, fill opacity=0.3,
},
kwad/.style={
above left offset={-0.1,0.23},
below right offset={0.10,-0.36},
#1
},
pion/.style={
above left offset={-0.07,0.2},
below right offset={0.07,-0.32},
#1
},
poz/.style={
above left offset={-0.03,0.18},
below right offset={0.03,-0.3},
#1
},set fill color/.code={\pgfkeysalso{fill=#1}},
set border color/.style={draw=#1}
}
\[
% \mathbf{X} =
\begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
\matrix [mymatrix,inner sep=4pt] (m)
{
\tikzmarkin[kwad=style green]{Prime} v_{1,1} & v_{1,2} & \tikzmarkin[pion=style purple]{VL} v_{1,3} & \textcolor{white}{v_{1,4}} & & \textcolor{white}{v_{1,6}} \\
v_{2,1} & v_{2,2} & v_{2,3} & & & \\
\tikzmarkin[poz=style brown]{HL} v_{3,1} & v_{3,2} & \tikzmarkin[kwad=style orange]{Mix} v_{3,3} \tikzmarkend{Prime} &\tikzmarkin[pion=style purple]{VR} v_{3,4} \tikzmarkend{HL} & & \\
\textcolor{white}{v_{4,1}} & & \tikzmarkin[poz=style brown]{HR} v_{4,3} \tikzmarkend{VL}& \tikzmarkin[kwad=style cyan]{Bis} v_{4,4} \tikzmarkend{Mix} & v_{4,5} & v_{4,6} \tikzmarkend{HR} \\
& & & v_{5,4} & v_{5,5} & v_{5,6} \\
\textcolor{white}{v_{6,1}} & & & v_{6,4} \tikzmarkend{VR} & v_{6,5} & v_{6,6} \tikzmarkend{Bis} \\
};
% Braces
\mymatrixbraceright{1}{3}{$B'$}
\mymatrixbraceright{4}{6}{$B''$}
\mymatrixbracetop{1}{3}{$C'$}
\mymatrixbracetop{4}{6}{$C''$}
\mymatrixbracebottom{3}{3}{$F'$}
\mymatrixbracebottom{4}{4}{$F''$}
\mymatrixbraceleft{3}{3}{$E'$}
\mymatrixbraceleft{4}{4}{$E''$}
\end{tikzpicture}
\]
\end{document}
正如您所见,这确实产生了一个合理的结果,但在我看来,这完全是偶然的。您正在嵌套tikzpictures
。如果您要添加类似的东西scale=2
,结果将完全偏离,因为有些东西将被转换两次。实现缩放的一个选项是使用adjustbox
,如Martin Scharrer 指出。我让你或马丁·沙勒更明确地阐述这一点。
我建议采用另一种方式,这样你就不必嵌套tikzpicture
了。在我看来,这种方式也更优雅,因为它不需要任何手动调整,如样式pion
等。你的矩阵已经是一个节点矩阵,没有必要诉诸hf-tikz
。您可以改用fit
。当然,你能xshift
通过使用、yshift
和inner xsep
来移动轮廓并调整其高度inner ysep
。(我没有进一步清理您的代码,例如通过\textcolor{white}{...}
用其对应项替换 。)只需将其设置为所需值tikz
即可缩放此内容。\myscale
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,fit,backgrounds}
%opening
\title{}
\author{}
\begin{document}
\pgfmathsetmacro{\myscale}{2}
\pgfkeys{tikz/mymatrixenv/.style={decoration={brace},every left delimiter/.style={xshift=8pt},every right delimiter/.style={xshift=-8pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes,nodes in empty cells,
left delimiter={[},right delimiter={]},inner sep=1pt,outer sep=1.5pt,
column sep=8pt,row sep=8pt,nodes={minimum width=20pt,minimum height=10pt,
anchor=center,inner sep=0pt,outer sep=0pt,scale=\myscale,transform shape}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand*\mymatrixbraceright[4][m]{
\draw[mymatrixbrace] (#1.west|-#1-#3-1.south west) -- node[left=2pt] {#4} (#1.west|-#1-#2-1.north west);
}
\newcommand*\mymatrixbraceleft[4][m]{
\draw[mymatrixbrace] (#1.east|-#1-#2-1.north east) -- node[right=2pt] {#4} (#1.east|-#1-#2-1.south east);
}
\newcommand*\mymatrixbracetop[4][m]{
\draw[mymatrixbrace] (#1.north-|#1-1-#2.north west) -- node[above=2pt] {#4} (#1.north-|#1-1-#3.north east);
}
\newcommand*\mymatrixbracebottom[4][m]{
\draw[mymatrixbrace] (#1.south-|#1-1-#2.north east) -- node[below=2pt] {#4} (#1.south-|#1-1-#3.north west);
}
\tikzset{greenish/.style={
fill=green!50!lime!60,draw opacity=0.4,
draw=green!50!lime!60,fill opacity=0.1,
},
cyanish/.style={
fill=cyan!90!blue!60, draw opacity=0.4,
draw=blue!70!cyan!30,fill opacity=0.1,
},
orangeish/.style={
fill=orange!90, draw opacity=0.8,
draw=orange!90, fill opacity=0.3,
},
brownish/.style={
fill=brown!70!orange!40, draw opacity=0.4,
draw=brown, fill opacity=0.3,
},
purpleish/.style={
fill=violet!90!pink!20, draw opacity=0.5,
draw=violet, fill opacity=0.3,
}}
\[
% \mathbf{X} =
\begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
\matrix [mymatrix,inner sep=4pt] (m)
{
v_{1,1} & v_{1,2} & v_{1,3} & \textcolor{white}{v_{1,4}} & & \textcolor{white}{v_{1,6}} \\
v_{2,1} & v_{2,2} & v_{2,3} & & & \\
v_{3,1} & v_{3,2} & v_{3,3} & v_{3,4} & & \\
\textcolor{white}{v_{4,1}} & & v_{4,3} & v_{4,4} & v_{4,5} & v_{4,6} \\
& & & v_{5,4} & v_{5,5} & v_{5,6} \\
\textcolor{white}{v_{6,1}} & & & v_{6,4} & v_{6,5} & v_{6,6} \\
};
\begin{scope}[on background layer,rounded corners]
\node [fit=(m-1-1) (m-3-3),greenish,inner xsep=1.5pt,inner ysep=2.5pt]{};
\node [fit=(m-1-3) (m-4-3),purpleish,inner xsep=0.5pt,inner ysep=3.5pt]{};
\node [fit=(m-3-1) (m-3-4),brownish,inner xsep=0.5pt,inner ysep=1.5pt]{};
\node [fit=(m-3-3) (m-4-4),orangeish]{};
\node [fit=(m-3-4) (m-6-5),purpleish,inner xsep=0.5pt,inner ysep=3.5pt,yshift=1pt]{};
\node [fit=(m-4-3) (m-4-6),brownish]{};
\node [fit=(m-4-4) (m-6-6),cyanish,inner xsep=1.5pt,inner ysep=0.5pt,xshift=-1pt]{};
\end{scope}
% Braces
\begin{scope}[every node/.append style={scale=\myscale,transform
shape},very thick]
\mymatrixbraceright{1}{3}{$B'$}
\mymatrixbraceright{4}{6}{$B''$}
\mymatrixbracetop{1}{3}{$C'$}
\mymatrixbracetop{4}{6}{$C''$}
\mymatrixbracebottom{3}{3}{$F'$}
\mymatrixbracebottom{4}{4}{$F''$}
\mymatrixbraceleft{3}{3}{$E'$}
\mymatrixbraceleft{4}{4}{$E''$}
\end{scope}
\end{tikzpicture}
\]
\end{document}