更新

更新

我的 LaTeX 代码如下:

\documentclass{standalone}
\usepackage{times}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes,patterns}


\begin{document}
\begin{tikzpicture}

\node (A) [pattern=north west lines, minimum size = 5cm] at (0  , 0  ) {};
\node (B) [pattern=north east lines, minimum size = 5cm] at (4cm, 4cm) {};

\node [circle,draw=red,fill=red] at (A.center) {};
\node [circle,draw=red,fill=red] at (B.center) {};

\draw [|<->|,color=red,line width=1pt] ([yshift=6pt]A.north west) -- node [fill=white] {Cross} ([yshift=6pt]B.north west|-A.north);

\end{tikzpicture}
\end{document}

生成的PDF是:
在此处输入图片描述

但是当我使用下面的命令转换pdf文件时,并没有得到相同的结果,如下所示。事实上,结果是错误的,因为节点的边框Cross和黑线。

在此处输入图片描述


更新

将 pdf 转换为 jpg 的命令是

转换 test.pdf test.jpg

ImageMagic 的版本是

C:\users\test\> convert --version
Version: ImageMagick 7.0.3-2 Q16 x64 2016-10-02 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

我还使用以下命令测试了 png。

转换 test.pdf test.png

但问题仍然存在。

在此处输入图片描述

答案1

edge操作可用于绘制线段之间节点,无需设置节点背景。

\documentclass{standalone}
\usepackage{times}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes,patterns}

\begin{document}
\begin{tikzpicture}

\node (A) [pattern=north west lines, minimum size = 5cm] at (0  , 0  ) {};
\node (B) [pattern=north east lines, minimum size = 5cm] at (4cm, 4cm) {};

\node [circle,draw=red,fill=red] at (A.center) {};
\node [circle,draw=red,fill=red] at (B.center) {};

\coordinate (a) at ([yshift=6pt]A.north west);
\coordinate (b) at ([yshift=6pt]B.north west|-A.north);
% put the "Cross" node, without drawing line
\path (a) -- node[red] (c) {Cross} (b);
% draw line segments
\path[red,line width=1pt,->|] (c) edge (a) edge (b);

\end{tikzpicture}
\end{document}

答案2

感谢您的评论,我已经找到了此处提到的问题的解决方案。

解决方案如下:

在源中添加以下几行tex

\usetikzlibrary{backgrounds}
...
\begin{scope}[on background layer]
  \fill [color = white] (current bounding box.north west) rectangle (current bounding box.south east);
\end{scope}

相关内容