使用 tikz 的 spy 库操作 spy in 节点的内容

使用 tikz 的 spy 库操作 spy in 节点的内容

考虑以下代码:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{calc}
\usetikzlibrary{spy}

\begin{document}

\begin{tikzpicture}
  [spy using outlines={circle, magnification=7, size=3cm, connect spies}]

  \draw[->, very thick] (0,0) -- (5,0);
  \path (2,2) node[fill, rectangle, inner sep=2pt, minimum height=1cm] (n) {};

  \draw[dotted] (n.south west) -- (n.south west |- 0,0);
  \draw[dotted] (n.south east) -- (n.south east |- 0,0);

  \spy on ($(n.south east |- 0,0)!0.5!(n.south west |- 0,0)$) 
    in node at (3,-2);
\end{tikzpicture}

\end{document}

这是输出:

喵喵

存在两个问题:

  1. 虚线变成了几个点。我可以更改节点内的线条样式spy in(保持原始样式不变),以便点符号出现的频率更高,并且虚线spy in也以这样的方式出现在节点中吗?
  2. 我可以以某种方式引用节点或节点内的坐标吗spy in?那是因为我需要在两条虚线的放大版本之间绘制一个距离测量标记。

答案1

我觉得如果你想做出如此剧烈的改变,你可能根本不想使用间谍,而只是在圆形节点中画出你喜欢的任何东西。

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{calc}
\usetikzlibrary{spy}

\begin{document}

\begin{tikzpicture}
  [spy using outlines={circle, magnification=7, size=3cm, connect spies}]

  \draw[->, very thick] (0,0) -- (5,0);
  \path (2,2) node[fill, rectangle, inner sep=2pt, minimum height=1cm] (n) {};

  \draw[dotted] (n.south west) -- (n.south west |- 0,0);
  \draw[dotted] (n.south east) -- (n.south east |- 0,0);

  \draw  let \p1=($(n.south east)-(n.south west)$)
   in   ($(n.south east |- 0,0)!0.5!(n.south west |- 0,0)$)
   node[circle,draw,inner sep=0pt,minimum size=3cm/7](small){}
    (3,-2)
   node[circle,draw,inner sep=0pt,minimum size=3cm,
   path picture={
   \draw[line width=7*0.8pt] 
   (path picture bounding box.west) -- (path picture bounding box.east);
   \draw[thick,dotted] (-7*\x1/2,0) --  (-7*\x1/2,3) 
    (7*\x1/2,0) --  (7*\x1/2,3); 
   \draw[|<->|] (-7*\x1/2,0.8) -- (7*\x1/2,0.8)
    node[midway,fill=white,minimum size=0pt,rectangle]{$\Delta x$};  }]
   (big){} (small) -- (big);
\end{tikzpicture}

\end{document}

在此处输入图片描述

您可以使用它来注释spy节点。

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{calc}
\usetikzlibrary{spy}

\begin{document}

\begin{tikzpicture}
  [spy using outlines={circle, magnification=7, size=3cm, connect spies}]

  \draw[->, very thick] (0,0) -- (5,0);
  \path (2,2) node[fill, rectangle, inner sep=2pt, minimum height=1cm] (n) {};

  \draw[densely dotted] (n.south west) -- (n.south west |- 0,0);
  \draw[densely dotted] (n.south east) -- (n.south east |- 0,0);

  \spy on ($(n.south east |- 0,0)!0.5!(n.south west |- 0,0)$) 
    in node at (3,-2);
  \draw  let \p1=($(n.south east)-(n.south west)$),\n1={7*\x1/2-7*0.2pt}
   in  (3,-2)
   node[circle,draw,inner sep=0pt,minimum size=3cm,
   path picture={
   \draw[|<->|] (-\n1,0.8) -- (\n1,0.8)
    node[midway,fill=white,minimum size=0pt,rectangle]{$\Delta x$};  }]
   (big){}; 
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容