# Tikz: faded node border has spurious extra border line

I'm adding borders to some tikz drawings in my document. Some are just images inside a tikz environment and some are full on drawings.

Using existing Q&A from here (most specifically Including an image with a faded border I've used the initial code as I want a constant grey fade rather than fading out the image as they all have white backgrounds) I've got the look I want although on compile I'm getting an extra thin grey line at the edge of my fade. This disappears completely when I comment out the framenode line at the end and set the start to:

\node (image)at (0,0) %[square,draw,line width=3mm]


so I'm sure I'm missing something in the frame set up that was not obvious in the answer I linked above.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}
\tikzstyle arrowstyle=[scale=1]
\tikzstyle arrowstyle2=[scale=2]
\tikzstyle directed=[postaction={decorate,decoration={markings,
mark=at position .65 with {\arrow[arrowstyle]{stealth}}}}]
\tikzstyle reverse directed=[postaction={decorate,decoration={markings,
mark=at position .65 with {\arrowreversed[arrowstyle]{stealth};}}}]
\tikzstyle directed2=[postaction={decorate,decoration={markings,
mark=at position 1 with {\arrow[arrowstyle2]{stealth}}}}]
\tikzstyle reverse directed2=[postaction={decorate,decoration={markings,
mark=at position 0 with {\arrowreversed[arrowstyle2]{stealth};}}}]

% this "frames" a rectangle node
\newcommand\framenode[2][10pt]{
\fill[white,path fading=fade u] (#2.south west) rectangle ($(#2.south east)+(0, #1)$);
\fill[white,path fading=fade d] (#2.north west) rectangle ($(#2.north east)+(0,-#1)$);
\fill[white,path fading=fade l] (#2.south east) rectangle ($(#2.north east)+(-#1,0)$);
\fill[white,path fading=fade r] (#2.south west) rectangle ($(#2.north west)+( #1,0)$);
}

\begin{document}

\begin{tikzpicture}[square/.style={regular polygon,regular polygon sides=4}]
\node (image)at (0,0) [square,draw,line width=3mm]
{
\begin{tikzpicture}
% define coordinates
\coordinate (O) at (0,0) ;
\coordinate (A) at (0,4) ;
\coordinate (B) at (0,-4) ;
\coordinate (C) at (-4,-4) ;
% media
\node[left] at (-2,-2) {House};
\node[right] at (-1,-2) {h};
\node[] at (1,-5) {d};
\node[] at (-1,2.25) {l};
\node[] at (1.5, -1.25) {\textbf{v}};
% axis
\draw[directed2, dash pattern=on5pt off3pt] (O) -- (-50:2.5) ;
\draw[dash pattern=on5pt off3pt] (-4,0) -- (4,0);
\draw[directed2] (2,3) -- (3,3);
\draw[directed2] (2,3) -- (2,2);
\node[] at (3.5, 3) {\textbf{i}};
\node[] at (2, 1.5) {\textbf{j}};
\draw[directed2] (3,-2) -- (3, -3);
\node[] at (3.5, -2.5) {\textbf{g}};
% lines
\draw[red,ultra thick,reverse directed] (O) -- (130:5.2);
\draw[black, directed2, reverse directed2] (0.25,0.25) -- (-3,4.25);
\draw[black, ultra thick] (O) -- (-90:4);
\draw[black, ultra thick] (C) -- (4,-4);
\draw[black, directed2, reverse directed2] (-0.5,-4) -- (-0.5,0);
\draw[black, directed2, reverse directed2] (0,-4.5) -- (2,-4.5);
\draw[red, ultra thick, directed, dash pattern=on5pt off3pt] plot [smooth] coordinates {(0,0) (0.65,-0.75) (1,-1.35) (2,-4)};
% angles
\draw (-1,0) arc (180:130:1);
\node[] at (335:-1.5) {$\alpha$};
\end{tikzpicture}
};
\framenode[35pt]{image}
\end{tikzpicture}
\end{document}


The effect is exactly what I want apart from the extra 1pt boarder at the edge of the fade - I'd be very grateful for any suggestions!

• It is very likely that this is a viewer issue. I don't get any problems here using Atril on Linux. Have you tried (a) zooming in and (b) using another viewer? – TeXnician Jan 5 '18 at 13:20
• Because you had part of the code selected when you inserted the image, you may see that there some markdown before \begin{document}, and that all [, ] has been changed to $, $. Could you re-insert the code so that is fixed? – Torbjørn T. Jan 5 '18 at 13:21
• code should be fixed now – Yssybyl Jan 5 '18 at 13:42
• Indeed, and I do not see that line either, so I suspect TeXnician is correct. – Torbjørn T. Jan 5 '18 at 13:49
• It still appears on zoom for me - looked on ShareLaTeX previewer (after compiling on their site, as well as compiling locally and viewing on Document Viewer and also on Atril on Ubuntu 16.04. Interestingly it does vanish on GoogleMail doc preview so that would agree with your assertion that it's a viewer issue. Clearly checking two different viewers wasn't enough. Thanks both – Yssybyl Jan 5 '18 at 13:53

as per the comments above, this was a viewer issue.

It appears to be a rendering issue in some viewers and depending on environment/zoom with either appear or not. The solution to prevent it appearing is to flatten the pdf.

I do this using the solution from: https://unix.stackexchange.com/questions/162922/is-there-a-way-to-flatten-a-pdf-image-from-the-command-line

pdf2ps orig.pdf - | ps2pdf - flattened.pdf


It is a viewer effect -- the line below your fading is seen at the border, but you can avoid it by making the fading a bit larger than necessary:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}

% this "frames" a rectangle node
\newcommand\framenode[2][10pt]{
\fill[white,path fading=fade u] ([yshift=-1pt]#2.south west)  rectangle ($([yshift=-1pt]#2.south east)+(0, #1)$);
\fill[white,path fading=fade d] ([yshift=1pt]#2.north west) rectangle ($([yshift=1pt]#2.north east)+(0,-#1)$);
\fill[white,path fading=fade l] ([xshift=1pt]#2.south east) rectangle ($([xshift=1pt]#2.north east)+(-#1,0)$);
\fill[white,path fading=fade r] ([xshift=-1pt]#2.south west) rectangle ($([xshift=-1pt]#2.north west)+( #1,0)$);
}

\begin{document}

\begin{tikzpicture}[square/.style={regular polygon,regular polygon sides=4}]
\node (image)at (0,0) [square,draw,line width=3mm]
{\rule{6cm}{6cm}};
\framenode[35pt]{image}

\end{tikzpicture}
\end{document}


• I'm still seeing a specific line using the MWE you posted above with a pale grey line into the corner that doesn't appear on your image. It's better than the original but doesn't remove it completely. I tried increasing the shift size but am always left with a thin line both locally and on ShareLaTeX – Yssybyl Jan 5 '18 at 14:54