我不知道为什么,但是我不能使用带圆角的装饰。以下 MWE 失败ERROR: Dimension too large.
:
\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}[main style/.style={
rectangle,draw,fill=blue!30,decorate,
decoration={zigzag,segment length=1mm,amplitude=.5mm}
}]
% Ok
\node[main style] at (0,0) {ABC};
% Fails
\node[main style, rounded corners] at (0,-1) {DEF};
\end{tikzpicture}
\end{standaloneframe}
\end{document}
答案1
这类装饰可能会发生这种情况。如果您选择的步长或幅度太小,或者执行类似 的操作rounded corners
,您可能会收到dimension too large errors
。但是,对我来说,zigzag
圆角的 看起来像snake
。所以也许这是可行的方法。
\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}[main style/.style={
rectangle,draw,fill=blue!30,decorate,
decoration={zigzag,segment length=1mm,amplitude=.5mm}
},round main style/.style={
rectangle,draw,fill=blue!30,decorate,
decoration={snake,segment length=1mm,amplitude=.5mm}}]
% Ok
\node[main style] at (0,0) {ABC};
% Fails
\node[round main style] at (0,-1) {DEF};
\end{tikzpicture}
\end{standaloneframe}
\end{document}
更新:感谢您澄清您的请求。我认为,这里有一些东西可以满足您的要求,并且基于Loop Space 的这个很好的答案也杰克的完整正弦和我对你的伴侣问题的回答。
\documentclass[beamer,tikz,preview,border=3.14mm]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing,shapes.geometric,backgrounds}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
% based on https://tex.stackexchange.com/a/25689/121799
% actual code from https://tex.stackexchange.com/a/447546/121799
\pgfdeclaredecoration{zigzag cycle}{initial}{
\state{initial}[
width=+0pt,
next state=half up,
persistent precomputation={\pgfmathsetmacro\matchinglength{
\pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
\setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
}] {}
\state{half up}[
width=+.25\pgfdecorationsegmentlength,
next state=big down]
{\pgfcoordinate{zigzag-cycle-start}{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
\pgfpathmoveto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
}
\state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
width=+.5\pgfdecorationsegmentlength,
next state=big up]
{
\pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}}
}
\state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
width=+.5\pgfdecorationsegmentlength,
next state=big down]
{
\pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
}
\state{center finish}[width=0pt, next state=final]{
}
\state{final}
{
\pgfpathlineto{\pgfpointanchor{zigzag-cycle-start}{center}}
}
}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}[main style/.style={
rectangle,draw=none}]
% avoids the dimension too large error with ordinary zigzags
\node[save path=\pathA,main style, rounded corners=3mm,inner sep=5pt] at (0,0) {ABC};
\node[save path=\pathB,main style, rounded corners=3mm,inner sep=5pt] at (5,0) {ordinary zigzag};
\begin{scope}[on background layer]
\draw[decorate,decoration={zigzag,segment length=1mm,amplitude=.5mm},fill=blue!30] [use path=\pathA];
\draw[decorate,decoration={zigzag,segment length=1mm,amplitude=.5mm},fill=blue!30] [use path=\pathB];
\end{scope}
% closed zigzag (it is OK to overwrite \pathA and \pathB after they have done their job)
\node[save path=\pathA,main style, rounded corners=3mm,inner sep=5pt] at (0,-2) {ABC};
\node[save path=\pathB,main style, rounded corners=3mm,inner sep=5pt] at (5,-2) {zigzag cycle};
\begin{scope}[on background layer]
\draw[decorate,decoration={zigzag cycle,segment length=1mm,amplitude=.5mm},fill=blue!30,sharp corners] [use path=\pathA];
\draw[decorate,decoration={zigzag cycle,segment length=1mm,amplitude=.5mm},fill=blue!30,sharp corners] [use path=\pathB];
\end{scope}
\end{tikzpicture}
\end{standaloneframe}
\end{document}
答案2
(我知道这是一个老问题,但我刚刚回答了一个类似的问题,这让我想到了这个问题,并且我在 PGF 代码中挖了一些...)
正如其他答案所解释的那样,问题在于rounded corners
当应用装饰时, 仍然有效,这会导致问题。使用路径,则可以在rounded corners
构建路径后关闭,因为在适当的接合处插入键很容易。使用节点路径,则所有路径构建都在视线之外进行,这使得在正确的位置插入代码变得更加困难。
然而,在阅读有关装饰的文章时,我找到了/pgf/every decoration
关键,这就是解决一切简而言之,通过将密钥放入sharp corners
此密钥中,我们可以rounded corners
在应用装饰之前禁用它,这似乎是银子弹解决这个问题。把它放在文档前言中可能足够安全,但它也可以在每个路径上使用它。
\documentclass{article}
%\url{https://tex.stackexchange.com/q/447533/86}
\usepackage{tikz}
\usetikzlibrary{
positioning,
decorations.pathreplacing,
decorations.pathmorphing
}
\tikzset{
disable rounded corners for decorations/.style={
/pgf/every decoration/.style={
/tikz/sharp corners
},
}
}
\begin{document}
\begin{tikzpicture}[
main style/.style={
rectangle,
draw,
fill=blue!30,
disable rounded corners for decorations,
decorate,
decoration={
zigzag,
segment length=1mm,
amplitude=.5mm
}
}
]
% Ok
\node[main style] at (0,0) {ABC};
% Fails
\node[main style, rounded corners] at (0,-1) {DEF};
\end{tikzpicture}
\end{document}
(请注意,这并不能修复Dimension too large
错误!)
这是一个更明显的例子:
\node[main style, rounded corners=1cm,minimum size=3cm] at (0,-3) {DEF};
左边是没有禁用键,右边是。