Sunday, June 9, 2013

Arrowheads in TiKZ

For most publication graphics (including drawings used in blog posts), I favor the TiKZ package for LaTeX. Many of those drawings have included lines with arrowheads, and the arrowheads never posed any problems ... until recently. Consider the following small chunk of TiKZ code:

\begin{tikzpicture}
   \draw[->] (0,0) -- (1,1);
\end{tikzpicture}

and the similar chunk

\begin{tikzpicture}[>=latex]
   \draw[->] (0,0) -- (1,1);
\end{tikzpicture}

Both should draw a diagonal arrow, with the arrowheads differing only in terms of their style. (The optional argument in the first line of the second version specifies the use of LaTeX-style arrowheads.) Indeed, when compiling the document with latex (producing DVI output), ps2pdf (producing PDF output by way of an intermediate Postscript file) or XeTeX, I get the expected output:
output produced by ps2pdf: two line segments with arrowheads
On the other hand, when I compile the document with pdflatex (the program I normally use) or LuaTeX, the arrow head in the first version goes missing:

output produced by pdflatex: two line segments with an arrowhead only on the second
(As a sidebar, compiling with dvipdfm, which I never use, produces a PDF file with a single blank page.)

This occurs on a Linux Mint 14 (Nadia) system with the TeXLive 2012 LaTeX distribution. As I said, the problem is new to me. I've previously drawn arrows in TiKZ using TeXLive (perhaps the 2011 or 2010 version) without specifying LaTeX-style arrowheads and compiled successfully using pdflatex. The workaround is at least straightforward. I just have to remember to specify the arrowhead style.

On an unrelated note, if anyone is curious how I converted the PDF output to the PNG images above, I took a somewhat circular route. For whatever reason, the ImageMagick convert utility, which on a good day requires specification of various command line options to produce  decent looking PNG, insisted on producing empty image files from my PDF files. So I opened each PDF file in a viewer, took a screen capture by pressing Control-PrtScn, and pasted the image into IrfanView (running under WINE). In IrfanView, which has excellent image manipulation tools, I just cropped the image and saved it to a PNG file.

2 comments:

  1. If you end up needing to do more screen capture & annotation http://shutter-project.org/ is a good package (for linux) to check out.

    ReplyDelete
    Replies
    1. Thanks for the suggestion. I actually tried Shutter before going to IrfanView, but the PNG file I got from Shutter was badly pixelated. I'm not sure why; I've had good luck with Shutter before. I was using Evince to view the PDF image; I didn't think to try a Shutter capture of an Acrobat Reader window to see if that might have better resolution.

      Delete

Due to intermittent spamming, comments are being moderated. If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on Operations Research Stack Exchange.