我正在尝试缩放整个图片,但没有成功。
\begin{tikzpicture} [scale=0.5, every node/.style={transform shape}]
\tikzstyle{startstop} = [ellipse, draw=orange, thick, fill=orange!20, text width=5em, minimum height=4em, text centered, dashed]
\tikzstyle{block} = [rectangle, draw=blue, thick, fill=blue!20, text width=8em, minimum height=4em, shape aspect=2, text centered, rounded corners]
% Define nodes in a matrix
\matrix [column sep=10mm, row sep=7mm]
{
\node [startstop] (Signal) {Trama de la señal};
&\node [block] (DFT) {Transformada Discreta de Fourier};
&\node [block] (Module) {Módulo};
&\node [block] (MelFilt) {Filtros Mel}; \\
\node [startstop] (MFCC) {MFCC};
&\node [block] (Lifter) {Lifter};
&\node [block] (IDCT) {Transformada Discreta Inversa de Coseno};
&\node [block] (Log) {Logaritmo}; \\
};
\node [draw, scale=1, rectangle, dashed, thick, fit=(DFT) (Module) (Log) (Lifter) (IDCT)] {};
% connect all nodes DFT above
\begin{scope} [every path/.style={line, line width=1.3pt} ]
%Down Lines
\path (Signal) -- (DFT);
\path (DFT) -- (Module);
\path (Module) -- (MelFilt);
\path (MelFilt.south) -- (Log.north);
\path (Log) -- (IDCT);
\path (IDCT) -- (Lifter);
\path (Lifter) -- (MFCC);
\end{scope}
\end{tikzpicture}
当我更换变换形状为了比例=0.5,拟合失败。
答案1
我认为问题出在矩阵上。当我切换到常规节点时,它就开始工作得更好了。我也不认为矩阵在这里是合适的工具,因为它的工作方式有点不同。或者,我建议使用库,chains
它也会摆脱下面多余的行命令。最后,您可以删除库fit
并使用calc
在节点周围绘制一个合适的矩形(顺便说一下,您只需要两个就可以拟合它们)。
当然,现在它的扩展性更好了!
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, chains, calc}
\tikzset{
startstop/.style={ellipse, draw=orange, thick, fill=orange!20, text width=5em, minimum height=4em, text centered, dashed},
block/.style={rectangle, draw=blue, thick, fill=blue!20, text width=8em, minimum height=4em, shape aspect=2, text centered, rounded corners},
links/.style={line width=1.3pt}
}
\begin{document}
\begin{tikzpicture}[scale=.5,transform shape,
start chain=going right, node distance=1cm, auto,
every join={line width=1.3pt},
every node/.style={on chain, join}
]
% Define nodes in a matrix
\node[startstop] (Signal) {Trama de la señal};
\node[block] (DFT) {Transformada Discreta de Fourier};
\node[block] (Module) {Módulo};
\node[block] (MelFilt) {Filtros Mel};
\node[continue chain=going below,block] (Log) {Logaritmo};
\node[continue chain=going left, block] (IDCT) {Transformada Discreta Inversa de Coseno};
\node[continue chain=going left, block] (Lifter) {Lifter};
\node[continue chain=going left, startstop] (MFCC) {MFCC};
% connect all nodes DFT above
\draw[dashed, thick, rounded corners] ($(Lifter.south west)+(-.2,-.2)$) rectangle ($(MelFilt.north east)+(.2,.2)$);
\end{tikzpicture}
\end{document}
答案2
来自 TikZ 手册:
可以变换节点,但默认情况下,变换不适用于节点。原因是,即使主图形变换,您通常也不希望文本缩放或旋转。缩放文本是邪恶的,旋转则没那么邪恶。但是,有时您确实希望变换节点,例如,有时将节点旋转 90 度肯定是有意义的。有两种方法可以实现这一点:
您可以使用以下选项:
/tikz/transform 形状(无值)
使当前的“外部”变换矩阵应用于形状。例如,如果您说 \tikz[scale=3],然后说 node[transform shape] {X},您将在图形中得到一个“巨大的”X。
- 您可以在节点的选项列表中提供转换选项。这些转换始终适用于节点。
因此,如果可能的话,请避免扩展!如果您仍然坚持,请按照以下方式将其作为您的 MWe:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,matrix,shapes.geometric}
\begin{document}
\begin{tikzpicture} [
every node/.style = {scale=0.5, transform shape, % <-----
align=center, minimum height=4em},
startstop/.style = {ellipse, draw=orange, thick, dashed,
fill=orange!20, text width=5em},
block/.style = {rectangle, draw=blue, thick, rounded corners,
fill=blue!20, text width=8em}
]
% Define nodes in a matrix
\matrix [column sep=10mm, row sep=7mm]
{
\node[startstop] (Signal) {Trama de la señal};
& \node [block] (DFT) {Transformada Discreta de Fourier};
& \node [block] (Module) {Módulo};
& \node [block] (MelFilt) {Filtros Mel}; \\
\node [startstop] (MFCC) {MFCC};
& \node [block] (Lifter) {Lifter};
& \node [block] (IDCT) {Transformada Discreta Inversa de Coseno};
& \node [block] (Log) {Logaritmo}; \\
};
\node[draw, dashed, thick,
scale=2, % <-----
fit=(DFT) (Log)] {};
% connect all nodes DFT above
\draw[line width=1.3pt,->]
(Signal) edge (DFT)
(DFT) edge (Module)
(Module) edge (MelFilt)
(MelFilt) edge (Log)
(Log) edge (IDCT)
(IDCT) edge (Lifter)
(Lifter) edge (MFCC);
\end{tikzpicture}
\end{document}
代码中的主要更改以 表示<---
。其他更改仅略微优化了代码并(根据我的喜好)改善了外观。当然,无需缩放即可获得更好的外观。
如您所见,蓝色节点所在的节点将使用节点缩放的逆值重新缩放。这是必要的,因为对于拟合节点来说,它不必缩放。
结果是:
答案3
目前还不清楚您是否还想缩放文本。但这里有很多关于这个主题的帖子。对于您的示例,transform canvas={scale=.5}
应该可以。这是您想要的吗?
请注意,我必须line
从您的中删除该样式scope
,因为我不知道它来自哪里。
% arara: pdflatex
\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes, fit}
\begin{document}
\begin{tikzpicture}[%
,transform canvas={scale=.5}
,startstop/.style={%
,ellipse
,draw=orange
,thick
,fill=orange!20
,text width=5em
,minimum height=4em
,text centered
,dashed
}
,block/.style={%
,rectangle
,draw=blue
,thick
,fill=blue!20
,text width=8em
,minimum height=4em
,shape aspect=2
,text centered
,rounded corners
}
]
% Define nodes in a matrix
\matrix[column sep=10mm, row sep=7mm]
{%
\node [startstop] (Signal) {Trama de la señal};
&\node [block] (DFT) {Transformada Discreta de Fourier};
&\node [block] (Module) {Módulo};
&\node [block] (MelFilt) {Filtros Mel}; \\
\node [startstop] (MFCC) {MFCC};
&\node [block] (Lifter) {Lifter};
&\node [block] (IDCT) {Transformada Discreta Inversa de Coseno};
&\node [block] (Log) {Logaritmo}; \\
};
\node[draw, rectangle, dashed, thick, fit=(DFT) (Module) (Log) (Lifter) (IDCT)] {};
% connect all nodes DFT above
\begin{scope}[every path/.style={draw,line width=1.3pt}]
\path (Signal) -- (DFT);
\path (DFT) -- (Module);
\path (Module) -- (MelFilt);
\path (MelFilt.south) -- (Log.north);
\path (Log) -- (IDCT);
\path (IDCT) -- (Lifter);
\path (Lifter) -- (MFCC);
\end{scope}
\end{tikzpicture}
\end{document}