I have a tikz picture that is basically some rectangles filled with simple commands such as


Nothing fancy.

I save them as a standalone, and then using imagemagics convert.exe I run

convert -density 900 mypdf.pdf mypng.png

for maximum quality. However, sometimes the render is not right, there are gaps between the fill and the border of the shapes, as you can see in some of the figures. Note how this also happens with circles and other shapes. Note also how only sometimes happens, and this effect is not unique to black.

How can I fix this?

Note: A specific fix for a single command/color combination does not work as I do have a wide variety of shapes and color sin different cases and lot of them show this effect. I know I can do \fill, but there are different color boundaries and color backgrounds. I understand that "redo the entire thing with better commands" may be a valid answer, but that is not the one I am asking about.

enter image description here

enter image description here




\draw[rounded corners=0.5mm,black,fill=Gray!10](0.1,0.1)rectangle (-0.2,0.9){};
\draw[rounded corners=0.5mm,black,fill=Gray!10](1.9,0.1)rectangle (2.2,0.9){};


\draw[fill=white] (-0.1,0.8) circle (0.04);
\draw[fill=white] (-0.1,0.2) circle (0.04);
\draw[fill=white] (2.1,0.8) circle (0.04);
\draw[fill=white] (2.1,0.2) circle (0.04);
\draw[black,thick,fill=Gray!10](0.1,0.1)rectangle (0.6,0.9){};

\draw[black,fill=Black](1.6,0.45)rectangle (1.8,0.55){};

\draw[fill=black] (1.6,0.2) circle (0.06);
  • Can you try \fill[Black](0.8,0.55)--(1.2,0.55)--(1.2,0.9)--(0.8,0.9)--cycle;? Commented Aug 7, 2018 at 11:42
  • @samcarter well, yeah, but it doesn't only happen with black. I still want a border in the ones that are not black. Commented Aug 7, 2018 at 11:43
  • 1
    You could replace the non-black rectangles with two rectangles. A black bigger one below and a smaller red one above. Commented Aug 7, 2018 at 11:44
  • @samcarter as you can see with the new image, it happens in general. Is the only option just duplicating everything so that there is a command for fill and a command for the border? Commented Aug 7, 2018 at 11:47
  • Maybe tex.stackexchange.com/a/328293/36296 could help (I did not test) Commented Aug 7, 2018 at 11:47

1 Answer 1


It's possible to remove the artefacts by not using anti-aliasing in the conversion.

e.g., directly with ghostscript:

gs -dSAFER -dNOPAUSE -dBATCH -sOutputFile=mypng.png -sDEVICE=pngalpha -r900 -dTextAlphaBits=1 -dGraphicsAlphaBits=1 mypdf.pdf

To avoid the jagged edges, then you could render it at a higher resolution and then re-sample it back down.

  • 1
    For completeness, in imagemagic convert the option is +antialias. Commented Aug 7, 2018 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .