自动侦察位置

自动侦察位置

我有使用 tikz 代码生成的此信息。我想使用 tikzlibrary 放大文本的某些部分spy,但我无法做到这一点。我想放大整个文本的这一部分4.96 billion

这是我的最小工作示例:

\title{A Very Simple \LaTeXe{} Template}
\author{
}
\date{\today}

\documentclass[12pt]{report}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\usepackage{tikz}

\begin{document}
\maketitle

\begin{center}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}
[spy using outlines={circle, magnification=2,size=2cm,connect spies}]
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
        The Indexed Web contains at least 4.96 billion pages (as of Wednesday, 11 June, 2014). -- WorldWideWebSize.com        
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Did you know?};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\spy[red] on (34.5:0.1) in node[right] at (0,-2.5);
\end{tikzpicture}%
\end{center}

\end{document}

这是我现在的输出,但我无法聚焦4.96 billion并放大它。事实上,我无法放大这段文字的任何部分spy,您可以从所附的照片中看到。 enter image description here

答案1

改变坐标后它就可以工作了:

\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}

\begin{center}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}[
  spy using outlines={circle, magnification=2,size=4.5cm,connect spies},
]
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
        The Indexed Web contains at least
        4.96 billion pages (as of
        Wednesday, 11 June, 2014). -- WorldWideWebSize.com
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Did you know?};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\spy[red] on (-2.375,.25) in node[right] at (-.5,-3.5);
\end{tikzpicture}%
\end{center}
\end{document}

Result

矩形

对于宽度较大的文本片段来说,圆形有点大,因此以下示例显示了一个矩形:

\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{spy}

\begin{document}

\begin{center}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}[
  spy using outlines={rectangle, magnification=2,size=4.5cm, height=2cm,connect spies},
]
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
        The Indexed Web contains at least
        4.96 billion
        pages (as of
        Wednesday, 11 June, 2014). -- WorldWideWebSize.com
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Did you know?};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\spy[red] on (-2.375,.25) in node[right] at (-1,-2);
\end{tikzpicture}%
\end{center}
\end{document}

Rectangle

椭圆

椭圆需要库shapes.geometric

\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{spy}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{center}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}[
  spy using outlines={ellipse, magnification=2,size=4.5cm, height=2cm,connect spies},
]
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
        The Indexed Web contains at least
        4.96 billion
        pages (as of
        Wednesday, 11 June, 2014). -- WorldWideWebSize.com
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Did you know?};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\spy[red] on (-2.375,.25) in node[right] at (-1,-2);
\end{tikzpicture}%
\end{center}
\end{document}

Ellipse

自动侦察位置

如果可以自动计算所监视的位置,那就太好了。TikZ 提供选项remember picture。然后 TikZ 图片的位置被写入文件.aux(通过\pdfsavepos)。然后可以从另一个 引用命名节点tikzpicture,因为 TikZ 知道绝对坐标并可以计算位置。

但是库有一个问题spy:它将保存tikzpicture到一个框中,并再次设置它以显示间谍窗口的缩放和剪辑视口。作为副作用,所有\writewhatsits 都执行了两次,包括位置标记(但现在在不同的位置)。更糟糕的是,位置标记由唯一标签标识。现在它们被复制为不同的值。当然,这会扰乱和弄乱结果。

以下示例使用包zref-savepos作为位置标记(也\tikzmark可以使用)。此外,.aux文件中的位置定义被包裹在宏\auxstartbillion和之间\auxstopbillion。第一次调用后,它们会重新定义自身以在再次调用时忽略其内容。这可以防止重复的标签。

size还可以计算间谍框(选项或width/ )的大小height。下面的示例使用了矩形。在文本周围添加了一点额外的空间,并且必须应用比例因子。

如果是圆形或椭圆形,则需要增加尺寸,因为指定的尺寸是整体边界框的尺寸,不考虑形状。

由于.aux涉及到文件,因此需要运行两次 LaTeX。

应用于矩形的示例:

\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{spy}
\usetikzlibrary{shapes.geometric}

\usepackage{zref-savepos}

\makeatletter
\newcommand*{\auxstartbillion}{}
\newcommand*{\auxstopbillion}{%
  \def\auxstartbillion##1\auxstopbillion{}%
}
\newcommand*{\auxwrite}[1]{%
  \if@filesw
    \write\@auxout{\detokenize{#1}}%
  \fi
}
\makeatother

\begin{document}

\begin{center}
\edef\SpyMag{2}
\edef\SpySep{\fboxsep}
\edef\SpyPosX{%
  \the\dimexpr
    (\zposx{billion-ll}sp + \zposx{billion-ur}sp)/2
    - \zposx{billion-origin}sp
  \relax
}
\edef\SpyPosY{%
  \the\dimexpr
    (\zposy{billion-ll}sp + \zposy{billion-ur}sp)/2
    - \zposy{billion-origin}sp
  \relax
}
\edef\SpyWidth{%
  \the\dimexpr(\zposx{billion-ur}sp - \zposx{billion-ll}sp + (\SpySep)*2)
  *\SpyMag\relax
}
\edef\SpyHeight{%
  \the\dimexpr(\zposy{billion-ur}sp - \zposy{billion-ll}sp + (\SpySep)*2)
  *\SpyMag\relax
}
\typeout{[debug] spy on (\SpyPosX, \SpyPosY)}%
\typeout{[debug] spy width=\SpyWidth, height=\SpyHeight}%
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}[
  spy using outlines={
    rectangle,
    magnification=2,
    width=\SpyWidth,
    height=\SpyHeight,
    connect spies,
  },
]
\node [mybox] (box){%
    \begin{minipage}{0.50\textwidth}
        The Indexed Web contains at least
        \sbox0{4.96~billion}%
        \auxwrite\auxstartbillion
        \raisebox{-\dp0}[0pt][0pt]{\zsavepos{billion-ll}}%
        \unhcopy0 %
        \raisebox{\ht0}[0pt][0pt]{\zsavepos{billion-ur}}%
        \ % space
        pages (as of
        Wednesday, 11 June, 2014). -- WorldWideWebSize.com
    \end{minipage}
};
\node[overlay](origin) at (0,0) {%
  \zsavepos{billion-origin}%
  \auxwrite\auxstopbillion
};
\node[fancytitle, right=10pt] at (box.north west) {Did you know?};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\spy[red] on (\SpyPosX,\SpyPosY) in node[right] at (-1,-2);
\end{tikzpicture}%
\end{center}
\end{document}

Calculated rectangle

相关内容