Tikzpicture 中出现意外间隙

Tikzpicture 中出现意外间隙

为了在我的文档中包含边距图,我大量使用以下代码。我复制/粘贴并修改了此处的一些代码,因此我并不完全理解代码。但是,当我包含用绘制的图时,它工作得很好pgfplots

但是当我使用它来包含 Tikz 图片时,发生了一些奇怪的事情。例如,对于这个 MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{xparse}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage{blindtext}
\usetikzlibrary{external}

\newcounter{maboite}
\setcounter{maboite}{1}


\newcommand\tikzmark[1]{
\tikz[remember picture,overlay]\node[inner xsep=0pt,outer sep=0pt] (#1) {};}
\NewDocumentCommand{\marginfig}{O{0pt}m}{%
\tikzexternaldisable
\stepcounter{maboite}%
\tikzmark{\themaboite}%

\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,yshift=-#1]
  (mybox\themaboite)
  at ([yshift=3pt]current page text area.east|-\themaboite) 
  {\parbox{5cm}{\tikzexternalenable #2}}; 
\end{tikzpicture}
\tikzexternalenable
}

\begin{document}

\marginfig[5cm]{
\begin{tikzpicture}
\draw [white,fill=BurntOrange!20] (0,0) circle (2);
\draw (0,0) node {$\bullet$};
\draw (0,0) node[below] {$a$};
\draw [fill=ForestGreen!20] (0.9,0.9) circle (0.6);
\draw (0.9,0.9) node {$\bullet$} node[below] {$x_1$};
\draw [fill=Orchid!20] (0,-1.65) circle (0.3);
\draw (0,-1.65) node {$\bullet$} node[below] {$x_2$};
\draw [fill=Cerulean!20] (-1.8,0) circle (0.15);
\draw (-1.8,0) node {$\bullet$} {};
\draw[<->,>=latex] (0,0) -- (2,0) node[midway,below] {$r$};
\end{tikzpicture}}

\blinddocument

\end{document}

该图如下所示: 在此处输入图片描述

而预期结果是: 在此处输入图片描述

有人能解释一下哪里出了问题吗?我该如何解决?

答案1

尝试替换:

\draw (0.9,0.9) node {$\bullet$} node[below] {$x_1$};

和:

\filldraw (0.9,0.9) circle (2pt) node[below, font=\scriptsize] {$x_1$}

等等...

我们:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{xparse}
\usepackage{mdframed}
\usepackage{tikzpagenodes}
\usepackage{blindtext}
\usetikzlibrary{external}
\newcounter{maboite}
\setcounter{maboite}{1}
\newcommand\tikzmark[1]{
\tikz[remember picture,overlay]\node[inner xsep=0pt,outer sep=0pt] (#1) {};}
\NewDocumentCommand{\marginfig}{O{0pt}m}{%
\tikzexternaldisable
\stepcounter{maboite}%
\tikzmark{\themaboite}%
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,yshift=-#1]
  (mybox\themaboite)
  at ([yshift=3pt]current page text area.east|-\themaboite) 
  {\parbox{5cm}{\tikzexternalenable #2}}; 
\end{tikzpicture}
\tikzexternalenable
}
\begin{document}
\marginfig[5cm]{
\begin{tikzpicture}
\draw [white,fill=BurntOrange!20] (0,0) circle (2);
\filldraw (0.,0.) circle (1.5pt) node[below, font=\scriptsize] {$a$};
\draw [fill=ForestGreen!20] (0.9,0.9) circle (0.6);
\filldraw (0.9,0.9) circle (1.5pt) node[below, font=\scriptsize] {$x_1$};
\draw [fill=Orchid!20] (0,-1.65) circle (0.3);
\filldraw (0,-1.65)  circle (1.5pt) node[below, font=\scriptsize] {$x_2$};
\draw [fill=Cerulean!20] (-1.8,0) circle (0.15);
\filldraw (-1.8,0)  circle (1.5pt);
\draw[<->,>=latex] (0,0) -- (2,0) node[midway,below] {$r$};
\end{tikzpicture}}
\blinddocument
\end{document}  

在此处输入图片描述

相关内容