TikZ:通过指定点的曲线

TikZ:通过指定点的曲线
\documentclass{standalone}
\usepackage{comment}

\usepackage{tikz,pgf}

\usetikzlibrary{fit,scopes,calc,matrix,positioning,decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
    \begin{scope}
            \matrix (A5) [matrix of nodes, ampersand replacement = \&] {
                {7}  \& {2} \& {7} \& {7} \& {2} \& {8}\\
            };
    \end{scope}
    \begin{scope}
        \matrix (B5) at ([yshift=-2.5cm]A5-1-1.south) [anchor=B5-1-1.north, matrix of nodes, ampersand replacement = \&] {
            {12} \& {7} \& {2} \& {7} \& {2} \& {8}\\
        };
    \end{scope}
    \path[draw] (A5-1-3.north west) -- (A5-1-4.north east) -- (B5-1-4.south east) -- (B5-1-4.south west) -- (A5-1-3.north west);
\end{tikzpicture}
\end{document}

这里\path[draw]将两个矩阵中的 7 组合在一起。有没有办法用更“弯曲”的曲线将它们组合在一起?即通过一些看起来不那么规则的曲线。

结果

答案1

像这样(请注意,我用 替换了你的最后一个坐标-- cycle)?

\draw [rounded corners=5pt]
  (A5-1-3.north west) -- (A5-1-4.north east) --
  (B5-1-4.south east) -- (B5-1-4.south west) -- cycle;

圆角

或者更像这样?

\draw
  [decoration={random steps,segment length=6pt,amplitude=1.5pt},
   decorate, rounded corners=2pt]
  (A5-1-3.north west) -- (A5-1-4.north east) --
  (B5-1-4.south east) -- (B5-1-4.south west) -- cycle

之字形

我更喜欢第一个,因为它看起来更符合印刷文本的风格。后者似乎有人攻击了你的论文 ;-)

附言:我不知道为什么曲折曲线不能自行闭合,也许有人可以修复这个问题,好吗?

答案2

将最后一行替换为:

\draw plot [smooth cycle,tension=0.3] coordinates {(A5-1-3.north west)  (A5-1-4.north east)  (B5-1-4.south east) (B5-1-4.south west)};

该选项smooth cycle会导致使用平滑曲线关闭点(因此您不会像原始代码中那样两次包含初始点)。

可以tension调整以适应。另请参阅TikZ 中的简单曲线

在此处输入图片描述

\documentclass{standalone}
\usepackage{comment}

\usepackage{tikz,pgf}

\usetikzlibrary{fit,scopes,calc,matrix,positioning,decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
    \begin{scope}
            \matrix (A5) [matrix of nodes, ampersand replacement = \&] {
                {7}  \& {2} \& {7} \& {7} \& {2} \& {8}\\
            };
    \end{scope}
    \begin{scope}
        \matrix (B5) at ([yshift=-2.5cm]A5-1-1.south) [anchor=B5-1-1.north, matrix of nodes, ampersand replacement = \&] {
            {12} \& {7} \& {2} \& {7} \& {2} \& {8}\\
        };
    \end{scope}
\draw plot [smooth cycle,tension=0.3] coordinates {(A5-1-3.north west)  (A5-1-4.north east)  (B5-1-4.south east) (B5-1-4.south west)};
\end{tikzpicture}
\end{document}

相关内容