如何自定义一个带有内部图形的矩形?

如何自定义一个带有内部图形的矩形?

参见我的 MWE:

\documentclass{scrartcl}

\usepackage{tikz}

\usetikzlibrary{
                positioning,
                datavisualization.formats.functions
               }
\tikzset{
         signal/.style = coordinate,
         block/.style = {
                         draw,
                         rectangle,
                         minimum height = 4em,
                         minimum width = 5em
                        },
         stepp/.style = {
                         block,
                         path picture = {
                                         \draw
                                           ([
                                             xshift = 5pt,
                                             yshift = 5pt
                                            ]path picture bounding box.south west) -| ([yshift = -5pt]path picture bounding box.north)
                                                                                   -- ([
                                                                                        xshift = -5pt,
                                                                                        yshift = -5pt
                                                                                       ]path picture bounding box.north east);
                                        }
                        },
         chirp/.style = {
                         block,
                         path picture = {
                                         \datavisualization[
                                                            xy Cartesian,
                                                            visualize as smooth line
                                                           ]
                                         data[format = function] {
                                                                  var x : interval[0 : pi];
                                                                  func y = sin(2 * pi * (1 + (500 - 1) / 2 / 10 * \value x) * \value x);
                                                                  %u(t) = sin(2pi(f_0 + (f_e - f_0) / 2t_e)t), with
                                                                  %start frequency f_0 in Hz,
                                                                  %end frequency f_e in Hz,
                                                                  %end time t_e in s and
                                                                  %time t in s
                                                                 };
                                        }
                        },
         saturation/.style = {
                              block,
                              path picture = {
                                              \draw
                                                [lightgray] ([yshift = 5pt]path picture bounding box.south) -- ([yshift = -5pt]path picture bounding box.north)
                                                            ([xshift = 5pt]path picture bounding box.west) -- ([xshift = -5pt]path picture bounding box.east);
                                              \draw
                                                ([
                                                  xshift = 7pt,
                                                  yshift = 10pt
                                                 ]path picture bounding box.south west) -- ([
                                                                                             xshift = -5pt,
                                                                                             yshift = 10pt
                                                                                            ]path picture bounding box.south)
                                                                                        -- ([
                                                                                             xshift = 5pt,
                                                                                             yshift = -10pt
                                                                                            ]path picture bounding box.north)
                                                                                        -- ([
                                                                                             xshift = -7pt,
                                                                                             yshift = -10pt]path picture bounding box.north east);
                                             }
                             },
         counter/.style = {
                           block,
                           path picture = {
                                           \node at (path picture bounding box.north east) {lim};
                                           \datavisualization[
                                                              xy Cartesian,
                                                              visualize as line
                                                             ]
                                           data {
                                                 x, y
                                                 0, 0
                                                 1, 0
                                                 1, 1
                                                 2, 1
                                                 2, 2
                                                 3, 2
                                                 3, 3
                                                 4, 3
                                                 4, 0
                                                 5, 0
                                                 5, 1
                                                 6, 1
                                                 6, 2
                                                 7, 2
                                                 7, 3
                                                 8, 3
                                                 8, 0
                                                };
                                          }
                          }
        }

\begin{document}

  \begin{tikzpicture}
    %placing the nodes
    \node[stepp] (step) {};
    \node[
          saturation,
          above = of step
         ] (saturation) {};
    \node[
          chirp,
          left = of saturation
         ] (chirp) {};
    \node[
          counter,
          below = of step
         ] (counter) {};
    \node[
          signal,
          right = of step
         ] (input) {};
    \node[
          block,
          right = of input
         ] (inputInterface) {};
    %connecting the nodes
    \foreach \i/\k in {
                       saturation/1,
                       counter/-1
                      } 
    {
     \draw
            (\i) -| ([yshift = \k*15pt]input);
     \draw
       [->] ([yshift = \k*15pt]input.east) -- ([yshift = \k*15pt]inputInterface.west);
    }
    \draw
      [->] (chirp) -- (saturation);
    \draw
      [->] (step) -- (inputInterface);
  \end{tikzpicture}

\end{document}

结果如下:

结果

左边四个方块中各需一个不同的图形。以下是给定的图形:叽叽喳喳饱和步柜台

我成功创建了其中两个。其余两个的代码也可用,但我没有将代码集成到块中。两个未完成的块的代码结果应该以某种方式缩放并移动到块内的正确位置。

欢迎提出任何解决方案!我非常希望对我的代码进行总体优化(很可能会有更高效、更直观的解决方案)!

提前感谢您的帮助和努力!

答案1

这是一个可能的解决方案。它不使用,datavisualization而是在块draw内使用常规。path picturecounter

对于chirpbloc ,我无法调整plot内部的功能path picture。作为替代方案,我定义了一个pic,它绘制在一个空块上。

\documentclass{scrartcl}

\usepackage{tikz}

\usetikzlibrary{
                positioning,
                datavisualization.formats.functions
               }
\tikzset{
    chirppic/.pic={
        \draw[scale=.5] plot[domain=0:pi, samples=50, smooth] (\x,{sin(2*pi*(1+(500-1)/2/10*\x)*\x)});
    },
    signal/.style = coordinate,
    block/.style = {
        draw,
        rectangle,
        minimum height = 4em,
        minimum width = 5em
    },
    stepp/.style = {
        block,
       path picture = {%
            \draw([shift={(5pt,5pt)}]path picture bounding box.south west) -| 
            ([yshift = -5pt]path picture bounding box.north) -- 
            ([shift ={(-5pt,-5pt)}]path picture bounding box.north east);
        }
    },
    chirp/.style = {
        block,
%       path picture = {%
%           \draw[scale=.5] (path picture bounding box.west)+   
%                   plot[domain=0:pi, samples=100] 
%                   (\x,{sin(2*pi*(1+(500-1)/2/10*\x)*\x)});        }
    },
    saturation/.style = {%
        block,
       path picture = {%
            \draw[lightgray] ([yshift = 5pt]path picture bounding box.south) -- 
                ([yshift = -5pt]path picture bounding box.north)
                ([xshift = 5pt]path picture bounding box.west) -- 
                ([xshift = -5pt]path picture bounding box.east);
            \draw([shift = {(7pt,10pt)}]path picture bounding box.south west) -- 
                ([shift ={(-5pt,10pt)}]path picture bounding box.south) -- 
                ([shift ={(5pt,-10pt)}]path picture bounding box.north) -- 
                ([shift ={(-7pt,-10pt)}]path picture bounding box.north east);
        }
    },
    counter/.style = {%
        block,
        label={[font=\sffamily\small, anchor=north west]north west:lim}, 
       path picture = {%
            \draw ([shift={(6pt,6pt)}]path picture bounding box.south west) 
            foreach \x in {1,...,6}{-|++(3pt,4pt)} -|++(3pt,-24pt)
            foreach \x in {1,...,6}{-|++(3pt,4pt)} -|++(3pt,-24pt);
        }
    }        
}

\begin{document}

  \begin{tikzpicture}
    %placing the nodes
    \node[stepp] (step) {};
    \node[
          saturation,
          above = of step
         ] (saturation) {};
    \node[
          chirp,
          left = of saturation
         ] (chirp) {};
    \pic at ([xshift=2mm]chirp.west) {chirppic}; 
    \node[
          counter,
          below = of step
         ] (counter) {};
    \node[
          signal,
          right = of step
         ] (input) {};
    \node[
          block,
          right = of input
         ] (inputInterface) {};
    %connecting the nodes
    \foreach \i/\k in {
                       saturation/1,
                       counter/-1
                      } 
    {
     \draw
            (\i) -| ([yshift = \k*15pt]input);
     \draw
       [->] ([yshift = \k*15pt]input.east) -- ([yshift = \k*15pt]inputInterface.west);
    }
    \draw
      [->] (chirp) -- (saturation);
    \draw
      [->] (step) -- (inputInterface);
  \end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

我终于找到了解决方案datavisualization,但是車輛改道

\documentclass{scrartcl}

\usepackage{tikz}

\usetikzlibrary{
                positioning,
                datavisualization.formats.functions
               }
\tikzset{
         signal/.style = coordinate,
         block/.style = {
                         draw,
                         rectangle,
                         minimum height = 4em,
                         minimum width = 5em
                        },
         stepp/.style = {
                         block,
                         path picture = {
                                         \draw
                                           ([
                                             xshift = 5pt,
                                             yshift = 5pt
                                            ]path picture bounding box.south west) -| ([yshift = -5pt]path picture bounding box.north)
                                                                                   -- ([
                                                                                        xshift = -5pt,
                                                                                        yshift = -5pt
                                                                                       ]path picture bounding box.north east);
                                        }
                        },
         saturation/.style = {
                              block,
                              path picture = {
                                              \draw
                                                [lightgray] ([yshift = 5pt]path picture bounding box.south) -- ([yshift = -5pt]path picture bounding box.north)
                                                            ([xshift = 5pt]path picture bounding box.west) -- ([xshift = -5pt]path picture bounding box.east);
                                              \draw
                                                ([
                                                  xshift = 7pt,
                                                  yshift = 10pt
                                                 ]path picture bounding box.south west) -- ([
                                                                                             xshift = -5pt,
                                                                                             yshift = 10pt
                                                                                            ]path picture bounding box.south)
                                                                                        -- ([
                                                                                             xshift = 5pt,
                                                                                             yshift = -10pt
                                                                                            ]path picture bounding box.north)
                                                                                        -- ([
                                                                                             xshift = -7pt,
                                                                                             yshift = -10pt]path picture bounding box.north east);
                                             }
                             }
        }

\begin{document}

  \newsavebox\counter
  \begin{lrbox}{\counter}
    \begin{tikzpicture}[scale = .195]
      \datavisualization[
                         xy Cartesian,
                         visualize as line
                        ]
      data {x, y
            0, 0
            1, 0
            1, 1.5
            2, 1.5
            2, 2.5
            3, 2.5
            3, 3.5
            4, 3.5
            4, 0
            5, 0
            5, 1.5
            6, 1.5
            6, 2.5
            7, 2.5
            7, 3.5
            8, 3.5
            8, 0
           };
    \end{tikzpicture}
  \end{lrbox}
  \newsavebox\chirp
  \begin{lrbox}{\chirp}
    \begin{tikzpicture}[scale = .5]
      \datavisualization[
                         xy Cartesian,
                         visualize as smooth line
                        ]
      data[format = function] {
                               var x : interval[0 : pi];
                               func y = sin(2 * pi * (1 + (500 - 1) / 2 / 10 * \value x) * \value x);
                               %u(t) = sin(2pi(f_0 + (f_e - f_0) / 2t_e)t), with
                               %start frequency f_0 in Hz,
                               %end frequency f_e in Hz,
                               %end time t_e in s and
                               %time t in s
                              };
    \end{tikzpicture}
  \end{lrbox}

  \begin{tikzpicture}
    %placing the nodes
    \node[stepp] (step) {};
    \node[
          saturation,
          above = of step
         ] (saturation) {};
    \node[
          block,
          left = of saturation
         ] (chirp) {\usebox\chirp};
    \node[
          block,
          below = of step,
          align=left
         ] (counter) {lim\\[.35\baselineskip]\usebox\counter};
    \node[
          signal,
          right = of step
         ] (input) {};
    \node[
          block,
          right = of input
         ] (inputInterface) {};
    %connecting the nodes
    \foreach \i/\k in {
                       saturation/1,
                       counter/-1
                      } 
    {
     \draw
            (\i) -| ([yshift = \k*15pt]input);
     \draw
       [->] ([yshift = \k*15pt]input.east) -- ([yshift = \k*15pt]inputInterface.west);
    }
    \draw
      [->] (chirp) -- (saturation);
    \draw
      [->] (step) -- (inputInterface);
  \end{tikzpicture}

\end{document}

相关内容