1

How do I achieve following graphic using tikz?

enter image description here

My attempt until now is

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}
        \draw (0,-3)--(0,3);
        \draw (4,-3)--(4,3);
        \draw (-.5,0)--(4.5,0);
        \draw [pattern = north east lines, pattern color = black] (0,-2) rectangle (4,2);
    \end{tikzpicture}   
\end{document}

which produces

enter image description here

How do I increase the spacing between the diagonal lines filling the rectangle?

  • Related: Drawing a circle in the complex plane, may just need to replace the circle in either answer with an appropriately-sized rectangle. – Mike Renfro Sep 2 '16 at 23:06
  • Thanks, I had a look at it but I think it is not exactly what I want. I added my progress to the question. – TheGeekGreek Sep 2 '16 at 23:32
4

TikZ defines north east lines using

\pgfdeclarepatternformonly{north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{4pt}{4pt}}{\pgfqpoint{3pt}{3pt}}%
{
  \pgfsetlinewidth{0.4pt}
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{3.1pt}{3.1pt}}
  \pgfusepath{stroke}
}

where it seems like it defines a rectangle from the first point to the second point and repeats starting at the third point.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{patterns}

\pgfdeclarepatternformonly{my lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{10pt}{10pt}}{\pgfqpoint{9pt}{9pt}}%
{
  \pgfsetlinewidth{0.4pt}
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{9.1pt}{9.1pt}}
  \pgfusepath{stroke}
}

\begin{document}

    \begin{tikzpicture}
        \draw (0,-3)--(0,3);
        \draw (4,-3)--(4,3);
        \draw (-.5,0)--(4.5,0);
        \draw [pattern = my lines, pattern color = black] (0,-2) rectangle (4,2);
    \end{tikzpicture}
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.