2

My LaTeX code is listed below:

\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}

The generated PDF is:
enter image description here

But when I converted the pdf file using the following command, I did not get the same result, as shown below. In fact, the result is wrong because of the border of the node Cross and the black line.

enter image description here


Update

The command used to convert pdf to jpg is

convert test.pdf test.jpg

The version of ImageMagic is

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

I also tested png using the following command.

convert test.pdf test.png

However, still the problem.

enter image description here

  • 2
    The used command for ImageMagick is missing, and I am not able to reproduce it using convert test.pdf test.jpg. For me this does not seem like a LaTeX problem. Instead of JPG I would probably use PNG to avoid problems with the used compression (something like convert -density 300 test.pdf test.png). – epR8GaYuh Mar 4 '18 at 9:22
  • 5
    As @ep said, PNG is the proper choice for artificial (drawn) graphical material. JPEG should only be used for photographs. – AlexG Mar 4 '18 at 9:42
  • 2
    Do you really need to fill=white the node background? This might be the reason for the artifact at the node edge produced by the JPEG algorithm. Anyways, don't use JPEG here. – AlexG Mar 4 '18 at 10:19
  • Viewer and rendering issues are off-topic. – Henri Menke Mar 5 '18 at 2:39
  • @AlexG Yes, I just need that the test on the line. This is the only way I have found. – aban Mar 5 '18 at 3:48
1

The edge operation could be used to draw line segments between nodes, removing the need for setting the node background.

\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}
0

Thanks for the comments, I have found the solution for the problem mentioned here.

Here is the solution:

Add the following lines into the tex source.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.