3

I'm afraid this question has been asked before, but I couldn't find it.

When I have an element in a tikzpicture environment that has a hatched filling, the filling becomes black when printing.

Example:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
\draw[pattern=north west lines, pattern color=black] (0,0) rectangle (2,4);
\end{tikzpicture}

\end{document}

I would prefer keeping the tikzpicture in my document and not copy and include it using \includegraphics. Can anybody tell me what I am doing wrong? Or are there solutions if this is a general problem?

Thanks in advance.

Hendrik
  • 133
  • I believe this problem is largely dependent on your setup. Have you tried printing the document on different printers? Is the result the same? When I print that pattern, the pattern is very dense, but not completely filled. One workaround could be to define your own pattern with more space between the pattern lines. – eiterorm Nov 07 '14 at 10:35
  • Thanks for your answer. Unfortunately, I only have access to this printer at the moment. If I include the figure with includegraphics, its totally fine, so I think it is about the pdf compilement. About my own pattern: I also tried dots (with less density) instead of lines and it didn't work either. – Hendrik Nov 10 '14 at 01:33

1 Answers1

0

It seems as if the rectangle background becomes black when printing and by using black hatched lines, the whole rectangle becomes black. I avoided this problem by using grey lines and define my own pattern as indicated by eiterorm.

Example as follows:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

%\usetikzlibrary{backgrounds}

\usepackage{tikz}
\usetikzlibrary{patterns}

% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
         hatchthickness/.code={\setlength{\hatchthickness}{#1}},
         hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
         hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=3pt,
         hatchthickness=0.4pt,
         hatchshift=0pt,% must be >= 0
         hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
   {custom north west lines}% name
   {\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
   {\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
   {\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
   {% shape description
    \pgfsetlinewidth{\hatchthickness}
    \pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
    \pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
    \ifdim \hatchshift > 0pt
      \pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
      \pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
    \fi
    \pgfsetstrokecolor{\hatchcolor}
%    \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
    \pgfusepath{stroke}
   }

\begin{document}

\begin{center}
%
\begin{tikzpicture}
\draw[pattern=custom north west lines] (0,0) rectangle (3,4);
\end{tikzpicture}%
%
\begin{tikzpicture}
\draw[pattern=custom north west lines,hatchspread=5pt,hatchthickness=2pt,hatchcolor=gray!20,] (0,0) rectangle (3,4);
\end{tikzpicture}%
%
\begin{tikzpicture}
\draw[pattern=custom north west lines,hatchspread=8pt,hatchthickness=5pt, hatchcolor=gray!20] (0,0) rectangle (3,4);
\end{tikzpicture}%
%
\begin{tikzpicture}
\draw[pattern=custom north west lines,hatchspread=10pt,hatchthickness=3pt, hatchcolor=gray!20] (0,0) rectangle (3,4);
\end{tikzpicture}%

\end{center}

\end{document}

There might be a more elegant solution by changing the actual background color though.

Hendrik
  • 133