3

Could somebody please help me? The north east and north west lines aren't working how I thought they would as it's just showing lots of little lines. I found this workaround which works perfectly. The only problem is that I need the south east lines to have the same gap between each line as the horizontal lines. I've tried playing with the values but I couldn't find what I needed. Any help would be great :D

I have a working knowledge of latex, so the simpler, the better :D

enter image description here

 \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz}
    \usepackage{sectsty}
    \usepackage{titlesec}
    \usetikzlibrary{patterns}
      \pgfdeclarepatternformonly{south west lines}{\pgfqpoint{-0pt}{-0pt}}{\pgfqpoint{3pt}{3pt}}{\pgfqpoint{3pt}{3pt}}{
            \pgfsetlinewidth{0.4pt}
            \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
            \pgfpathlineto{\pgfqpoint{3pt}{3pt}}
            \pgfpathmoveto{\pgfqpoint{2.8pt}{-0.2pt}}
            \pgfpathlineto{\pgfqpoint{3.2pt}{.2pt}}
            \pgfpathmoveto{\pgfqpoint{-.2pt}{2.8pt}}
            \pgfpathlineto{\pgfqpoint{.2pt}{3.2pt}}
            \pgfusepath{stroke}}
    
    \pgfdeclarepatternformonly{south east lines}{\pgfqpoint{-0pt}{-0pt}}{\pgfqpoint{3pt}{3pt}}{\pgfqpoint{3pt}{3pt}}{
        \pgfsetlinewidth{0.4pt}
        \pgfpathmoveto{\pgfqpoint{0pt}{3pt}}
        \pgfpathlineto{\pgfqpoint{3pt}{0pt}}
        \pgfpathmoveto{\pgfqpoint{.2pt}{-.2pt}}
        \pgfpathlineto{\pgfqpoint{-.2pt}{.2pt}}
        \pgfpathmoveto{\pgfqpoint{3.2pt}{2.8pt}}
        \pgfpathlineto{\pgfqpoint{2.8pt}{3.2pt}}
        \pgfusepath{stroke}}
    
    \begin{document}
    \begin{tikzpicture}
        \draw [pattern=south west lines, pattern color=red] (0,0)--(0,1)--(1,1)--(1,0)--cycle;
    \end{tikzpicture}
    
    
    \begin{tikzpicture}
        \draw [pattern=horizontal lines, pattern color=red] (0,0)--(0,1)--(1,1)--(1,0)--cycle;
    \end{tikzpicture}
    
    \end{document}

1 Answer 1

10

If you use patterns.meta instead, things become much easier. You can just set the distance between the lines, and their angle.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{patterns.meta}
\begin{document}
\begin{tikzpicture}
    \draw [pattern={Lines[angle=45,distance=4pt]},pattern color=red] 
    (0,0) rectangle (1,1);
\end{tikzpicture}


\begin{tikzpicture}
    \draw [pattern={Lines[angle=0,distance=4pt]},pattern color=red] 
    (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}

enter image description here

2
  • Ahh that's perfect and yet so simple. Thanks for that!! Commented Nov 15, 2020 at 22:29
  • 1
    Why this code return dashed lines on my conputer? imgur.com/a/UrfxT8u Commented Nov 1, 2023 at 2:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .