19

I'm including PDF images into my tikzpicture environment, and the line widths in the included images are different than in the original PDF (some are thick as they should be, some are thin).

input versus output][1

A minimal example would be:

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}[scale=2.7]
 \node (A) at (0,0) {\includegraphics{example1}};
 \end{tikzpicture}
\end{document}

How do I make tikzpicture keep the line widths in example1(.pdf)?

The picture can be downloaded at http://dl.dropbox.com/u/25315636/example1.pdf

Hendrik Vogt
  • 37,935
Bostjan
  • 191
  • 4
    Did you make sure that it's not just a display-issue of the PDF-reader? Some behave pretty badly with line-width. Try zooming in or printing the file to verify this. Otherwise, it's pretty hard to figure out without the actual file. I don't get different results with a random .pdf. – dhst Jul 02 '12 at 13:08
  • Why [scale=2.7]? In your example, the scaling do nothing ! – Alain Matthes Jul 02 '12 at 15:07
  • Yes, I am sure, I'm using the latest PDF reader, plus it is obvious from zooming (and printing). Indeed, the scale does nothing. I guess tikz somehow makes the imported PDF's to use the line widths of tikz instead its own widths... if that makes sense. – Bostjan Jul 02 '12 at 15:33
  • I have now included the image file. – Bostjan Jul 02 '12 at 15:41
  • 1
    That's weird! I've added an image to your question. Is this the same you get? – Hendrik Vogt Jul 02 '12 at 16:25
  • 1
    @HendrikVogt: I get the same result. Strange indeed! – Jake Jul 02 '12 at 16:33
  • @Bostjan: How did you generate that PDF image? – Jake Jul 02 '12 at 16:33
  • 1
    your linewidth in the pdf file is not correct. It can be seen when converting the pdf into an uncompressed one, e.g. with pdftk –  Jul 02 '12 at 16:58
  • Hm... it's saved directly from Adobe Illustrator. I can't imagine Adobe would produce a faulty PDF. Besides I tried to save it with various PDF compatibility versions and the result is always the same. – Bostjan Jul 02 '12 at 19:06
  • 1
    @Herbert: you are perfectly right! In this PDF file, first lines use current linewidth (regardless of its value), then other lines use explicitly 1 unit or 0.5 unit. Add 1 w at the beginning of the stream corrects this error. – Paul Gaborit Jul 04 '12 at 00:29
  • 1
    This found for me pdftops -level3 -eps example1.pdf example_1.eps and epstopdf example_1.eps solve the problem – Pablo González L Jul 04 '12 at 00:33

4 Answers4

15

As I already wrote in the comment, the pdf has a wrong linewidth setting. You can repair it by setting explicitly the linewidth:

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}[scale=2.7]
 \node (A) at (0,0) {\pdfliteral{ 1 w}\includegraphics{example1}};
 \end{tikzpicture}
\end{document}

yields the output: enter image description here

Xavier
  • 13,947
12

This is not a complete answer but solves the issue:

\documentclass{article}
\usepackage{tikz}


\begin{document}
 \begin{tikzpicture}[scale=2.7]
 \node (A) at (0,0) [line width=1pt]{\includegraphics{example1.pdf}};
 \end{tikzpicture}
 \includegraphics{example1}
\end{document}

It seems that tikz regards the badly drawn line as its own and applies the default drawing options on it. So its definitely under the tikz regime while it should not be. I could imagine, that your pdf isnt quite valid (some missing boxes maybe, remember pdf creator on Mac isnt perfect at all) or its just a bug.

bloodworks
  • 10,178
  • 1
    Your code proves that the first curves of this PDF file use the current value of linewidth instead of choosing their own value. – Paul Gaborit Jul 04 '12 at 00:35
5

Finally it seems that it's difficult to use Adobe Illustrator correctly (you need to fix the line width to avoid to use the current line width). So I propose to draw the picture only with TikZ.

Remark : I use a tikzpicture inside a tikzpicture intentionally. If you fix line width =1pt in the first tikzpicture, the current line width in the second one is 0.4pt.

\documentclass{article}
\usepackage{tikz} 
\usetikzlibrary{arrows} 
\begin{document}

\newcommand{\midarrow}{\tikz \draw[-stealth'] (0,0) -- +(.1,0);}
\newcommand{\revmidarrow}{\tikz \draw[-stealth' reversed] (0,0) -- +(.1,0);}

\begin{tikzpicture}
 \node (A) at (0,0) {%
\begin{tikzpicture}  
 \draw circle[radius=2];
\begin{scope}[line width = 1pt]
    \draw (-120:2) .. controls (-150:0.25) .. (-180:2) node[pos=.8,sloped,scale=2] {\revmidarrow};
    \draw (0:2)    .. controls (-30:0.25) ..  (-60:2)  node[pos=.8,sloped,scale=2] {\midarrow}; 
    \draw (120:2)  .. controls (160:.75) and (180:.5) .. (0:0) 
                   .. controls  (0:.5) and (20:.75)  .. (60:2) 
                      node [pos=.8,sloped,scale=2] {\midarrow}; 
\end{scope}
\end{tikzpicture}
};
\end{tikzpicture}
\end{document} 

enter image description here

Alain Matthes
  • 95,075
1

Try this:

First convert image file

pdftoeps -level3 -eps example1.pdf example_1.eps

Second reconvert image file

epstopdf example_1.eps

And try (and compare)

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (A) at (0,0) {\includegraphics[scale=1]{example_1.pdf}};
\end{tikzpicture}
\includegraphics[scale=1]{example1.pdf}
\includegraphics[scale=1]{example_1.pdf}
\end{document}

EDIT: Compare result, works for me TexLive 2012/Fedora 17/Acroread 9.5.1 EDIT2: Now works ...