我的图中箭头显示不正确。错误是什么?

我的图中箭头显示不正确。错误是什么?

我正在尝试编译以下代码以获取独立的 pdf 输出以便在另一个文档中使用它。

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle [radius=1cm];
\draw [dashed] (-2.1,0) circle [radius=1cm] ;
\draw [<-,thick] (-2.1,-1.4)--(0,-1.4) ;
\draw (-1,-1.2) node {$x_2$} ;
\draw (3,0) circle [radius = 0.7cm];
\draw [dashed](4.5,0)  circle [radius = 0.7cm];
\draw [->,thick] (3,-1.1) -- (4.5,-1.1);
\draw (3.75,-0.9) node {$x_2$};
\draw [dashed] (-2.1,0) -- (0,0);
\draw [dashed] (3,0) -- (4.5,0);
\draw  (0,0) -- (3,0) ;
\draw (0,-0.25) node {$-$} ;
\draw (-2.1,-0.25) node {$-$} ;
\draw (3,-0.25) node {$+$} ;
\draw (4.5,-0.25) node {$+$} ;
\draw (-1,1.2) node {$-q$} ;
\draw (3.75,1) node {$+q$} ;
\draw [->,ultra thick] (-2.1,1.75) -- (4.5,1.75) ;
\draw (4.7,1.75) node {E};
\draw (1.25,2) node {$\mu_i = q(x_1 + x_2)$};
\end{tikzpicture}
\end{document}

当我编译它时,我得到以下输出: 错误图片,箭头有一半超出文档底部

x2 下方的箭头只有一半可见。我该如何修复?

答案1

切换到较新的 TikZ 库arrows.meta。然后边界框计算包括箭头:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle [radius=1cm];
\draw [dashed] (-2.1,0) circle [radius=1cm] ;
\draw [<-,thick] (-2.1,-1.4)--(0,-1.4) ;
\draw (-1,-1.2) node {$x_2$} ;
\draw (3,0) circle [radius = 0.7cm];
\draw [dashed](4.5,0)  circle [radius = 0.7cm];
\draw [->,thick] (3,-1.1) -- (4.5,-1.1);
\draw (3.75,-0.9) node {$x_2$};
\draw [dashed] (-2.1,0) -- (0,0);
\draw [dashed] (3,0) -- (4.5,0);
\draw  (0,0) -- (3,0) ;
\draw (0,-0.25) node {$-$} ;
\draw (-2.1,-0.25) node {$-$} ;
\draw (3,-0.25) node {$+$} ;
\draw (4.5,-0.25) node {$+$} ;
\draw (-1,1.2) node {$-q$} ;
\draw (3.75,1) node {$+q$} ;
\draw [->,ultra thick] (-2.1,1.75) -- (4.5,1.75) ;
\draw (4.7,1.75) node {E};
\draw (1.25,2) node {$\mu_i = q(x_1 + x_2)$};
\end{tikzpicture}
\end{document}

结果

答案2

standalone除了加载箭头的 TikZ 库之外,您还可以做两件事。您可以通过将边框穿过来添加边框,\documentclass[border=10pt]...或者您可以通过添加类似以下内容来放大图形的边界框

\path (current bounding box.south) -- ++ (0,-10pt);

作为环境中的最后一行。

补充评论

您已将所有东西都牢牢地固定下来,如果您以后想调整的话,这会成为一场噩梦。在下面的代码中,我仅使用四个明确定义的坐标重写了您的图表,其他所有内容都是相对于这些坐标进行标识的。

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (-2.1,0);
  \coordinate (B) at (0,0);
  \coordinate (C) at (3,0);
  \coordinate (D) at (4.5,0);

  \draw          (B) circle [radius=1cm];
  \draw [dashed] (A) circle [radius=1cm] ;
  \draw          (C) circle [radius = 0.7cm];
  \draw [dashed] (D) circle [radius = 0.7cm];

  \draw [<-,thick] 
    ([yshift=-1.4cm]A) -- ([yshift=-1.4cm]B) 
    node[midway,above] {$x_2$};

  \draw [->,thick] 
    ([yshift=-1.1cm]C) -- ([yshift=-1.1cm]D) 
    node[midway,above] {$x_2$};

  \draw [dashed] 
    (A) -- (B) 
    node[midway,yshift=1.2cm] {$-q$}
    node[pos=0,below] {$-$};

  \draw [dashed] 
    (C) -- (D) 
    node[midway,yshift=1cm] {$+q$}
    node[pos=1,below] {$+$};

  \draw  
    (B) -- (C) 
    node[pos=0,below] {$-$} 
    node[pos=1,below] {$+$};

  \draw [->,ultra thick] 
    ([yshift=1.75cm]A) -- ([yshift=1.75cm]D)
    node[midway,above,inner sep=0pt] {$\mu_i = q(x_1 + x_2)$}
    node[pos=1,right] {E};

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容