Creating patternsFilling rectangle in TikZ with more than one colorTikZ: Cropping the Bounding BoxTikz: redefinition of patternsTikZ: Get values for predefined dash patternsCustom and built in TikZ fill patternsChange thickness of TikZ pattern library patternsPatterns in TikZPGFplots ybar patterns not showingCreating random patterns in TikZTikZ/ERD: node (=Entity) label on the insideCustom Fading for Rectangle
How to calculate a conditional PDF in mathematica?
What is this arch-and-tower near a road?
Does Evolution Sage proliferate Blast Zone when played?
How do both sides know the MTU
What units are kpts?
Do I need to be legally qualified to install a Hive smart thermostat?
What is the maximum amount of diamond in one Minecraft game?
Is it possible to spoof an IP address to an exact number?
Platform Event Design when Subscribers are Apex Triggers
Should I hide my travel history to the UK when I apply for an Australian visa?
What can a novel do that film and TV cannot?
how can i make this execution plan more efficient?
Interview Question - Card betting
Did Stalin kill all Soviet officers involved in the Winter War?
Sleepy tired vs physically tired
How to respond to someone who condemns behavior similar to what they exhibit?
What are the differences of checking a self-signed certificate vs ignore it?
Can 4 Joy cons connect to the same Switch?
Should I cheat if the majority does it?
Why do Klingons use cloaking devices?
What is meaning of 4 letter abbreviations in Roman names like Titus Flavius T. f. T. n. Sabinus?
Will electrically joined dipoles of different lengths, at right angles, behave as a multiband antenna?
How did שְׁלֹמֹה (shlomo) become Solomon?
Taking advantage when the HR forgets to communicate the rules
Creating patterns
Filling rectangle in TikZ with more than one colorTikZ: Cropping the Bounding BoxTikz: redefinition of patternsTikZ: Get values for predefined dash patternsCustom and built in TikZ fill patternsChange thickness of TikZ pattern library patternsPatterns in TikZPGFplots ybar patterns not showingCreating random patterns in TikZTikZ/ERD: node (=Entity) label on the insideCustom Fading for Rectangle
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Using north east hatch
from the answer to this question Filling rectangle in TikZ with more than one color I wanted to make a north west hatch
. However, it has funny teeth I do not know how to get rid of. What is wrong and how can I correct that?
MWE:
documentclassminimal
usepackagetikz
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
tikz-pgf
add a comment |
Using north east hatch
from the answer to this question Filling rectangle in TikZ with more than one color I wanted to make a north west hatch
. However, it has funny teeth I do not know how to get rid of. What is wrong and how can I correct that?
MWE:
documentclassminimal
usepackagetikz
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
tikz-pgf
add a comment |
Using north east hatch
from the answer to this question Filling rectangle in TikZ with more than one color I wanted to make a north west hatch
. However, it has funny teeth I do not know how to get rid of. What is wrong and how can I correct that?
MWE:
documentclassminimal
usepackagetikz
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
tikz-pgf
Using north east hatch
from the answer to this question Filling rectangle in TikZ with more than one color I wanted to make a north west hatch
. However, it has funny teeth I do not know how to get rid of. What is wrong and how can I correct that?
MWE:
documentclassminimal
usepackagetikz
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
tikz-pgf
tikz-pgf
asked 8 hours ago
PygmalionPygmalion
2,4933 gold badges26 silver badges54 bronze badges
2,4933 gold badges26 silver badges54 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
By enlarging the bounding box sufficiently, the problem is solved.
According to my calculations, it must be enlarged by at least 71%.
To simplify, I expanded it by an integer multiple of hatchdistance
.
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
hatch not really straight
The hatches are not perfectly straight (like the default ones in the patterns library) but they remain unchanged by scaling as shown in the above result.
Straight hatch
To do this, I enlarged the line that traces the hatching of an integer multiple hatchdistance
(noninteger multiples pose problems that I have not yet understood).
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
Code for really straight hatch:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (.6,0) rectangle +(1,1);
endtikzpicture
enddocument
Code for hatch that are not really straight:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (1,0) rectangle +(1,1);
endtikzpicture
enddocument
add a comment |
You do what one usually does: define the cell size a bit smaller than what the path actually covers. The problem is that if the width of the line exceeds 0.5pt
, an overshoot by 1pt
is no longer sufficient. So one may want to use a more generous overshoot. The following may be a bit "too generous" (but being
generous has no real sideeffects here AFAIK), and this one seems to work for many viewers and zoom levels, i.e. some of the things but not all in your code are also viewer issues.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint-hatchthickness-hatchthickness
pgfpathlinetopgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance+hatchthickness-hatchthickness
pgfpathlinetopgfqpoint-hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f498376%2fcreating-patterns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
By enlarging the bounding box sufficiently, the problem is solved.
According to my calculations, it must be enlarged by at least 71%.
To simplify, I expanded it by an integer multiple of hatchdistance
.
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
hatch not really straight
The hatches are not perfectly straight (like the default ones in the patterns library) but they remain unchanged by scaling as shown in the above result.
Straight hatch
To do this, I enlarged the line that traces the hatching of an integer multiple hatchdistance
(noninteger multiples pose problems that I have not yet understood).
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
Code for really straight hatch:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (.6,0) rectangle +(1,1);
endtikzpicture
enddocument
Code for hatch that are not really straight:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (1,0) rectangle +(1,1);
endtikzpicture
enddocument
add a comment |
By enlarging the bounding box sufficiently, the problem is solved.
According to my calculations, it must be enlarged by at least 71%.
To simplify, I expanded it by an integer multiple of hatchdistance
.
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
hatch not really straight
The hatches are not perfectly straight (like the default ones in the patterns library) but they remain unchanged by scaling as shown in the above result.
Straight hatch
To do this, I enlarged the line that traces the hatching of an integer multiple hatchdistance
(noninteger multiples pose problems that I have not yet understood).
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
Code for really straight hatch:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (.6,0) rectangle +(1,1);
endtikzpicture
enddocument
Code for hatch that are not really straight:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (1,0) rectangle +(1,1);
endtikzpicture
enddocument
add a comment |
By enlarging the bounding box sufficiently, the problem is solved.
According to my calculations, it must be enlarged by at least 71%.
To simplify, I expanded it by an integer multiple of hatchdistance
.
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
hatch not really straight
The hatches are not perfectly straight (like the default ones in the patterns library) but they remain unchanged by scaling as shown in the above result.
Straight hatch
To do this, I enlarged the line that traces the hatching of an integer multiple hatchdistance
(noninteger multiples pose problems that I have not yet understood).
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
Code for really straight hatch:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (.6,0) rectangle +(1,1);
endtikzpicture
enddocument
Code for hatch that are not really straight:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (1,0) rectangle +(1,1);
endtikzpicture
enddocument
By enlarging the bounding box sufficiently, the problem is solved.
According to my calculations, it must be enlarged by at least 71%.
To simplify, I expanded it by an integer multiple of hatchdistance
.
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
hatch not really straight
The hatches are not perfectly straight (like the default ones in the patterns library) but they remain unchanged by scaling as shown in the above result.
Straight hatch
To do this, I enlarged the line that traces the hatching of an integer multiple hatchdistance
(noninteger multiples pose problems that I have not yet understood).
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
Code for really straight hatch:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint2hatchdistance-hatchdistance
pgfpathlinetopgfqpoint-hatchdistance2hatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (.6,0) rectangle +(1,1);
endtikzpicture
enddocument
Code for hatch that are not really straight:
documentclass[tikz,border=5mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-1pt-1pt% below left
pgfqpointhatchdistancehatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint0pt0pt
pgfpathlinetopgfqpointhatchdistancehatchdistance
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchdistance-hatchdistance% below left
pgfqpoint2hatchdistance2hatchdistance% above right
pgfpointhatchdistance-1pthatchdistance-1pt%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance0pt
pgfpathlinetopgfqpoint0pthatchdistance
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange,scale=2] (1,0) rectangle +(1,1);
endtikzpicture
enddocument
edited 4 hours ago
answered 7 hours ago
AndréCAndréC
10.8k1 gold badge15 silver badges50 bronze badges
10.8k1 gold badge15 silver badges50 bronze badges
add a comment |
add a comment |
You do what one usually does: define the cell size a bit smaller than what the path actually covers. The problem is that if the width of the line exceeds 0.5pt
, an overshoot by 1pt
is no longer sufficient. So one may want to use a more generous overshoot. The following may be a bit "too generous" (but being
generous has no real sideeffects here AFAIK), and this one seems to work for many viewers and zoom levels, i.e. some of the things but not all in your code are also viewer issues.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint-hatchthickness-hatchthickness
pgfpathlinetopgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance+hatchthickness-hatchthickness
pgfpathlinetopgfqpoint-hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
add a comment |
You do what one usually does: define the cell size a bit smaller than what the path actually covers. The problem is that if the width of the line exceeds 0.5pt
, an overshoot by 1pt
is no longer sufficient. So one may want to use a more generous overshoot. The following may be a bit "too generous" (but being
generous has no real sideeffects here AFAIK), and this one seems to work for many viewers and zoom levels, i.e. some of the things but not all in your code are also viewer issues.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint-hatchthickness-hatchthickness
pgfpathlinetopgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance+hatchthickness-hatchthickness
pgfpathlinetopgfqpoint-hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
add a comment |
You do what one usually does: define the cell size a bit smaller than what the path actually covers. The problem is that if the width of the line exceeds 0.5pt
, an overshoot by 1pt
is no longer sufficient. So one may want to use a more generous overshoot. The following may be a bit "too generous" (but being
generous has no real sideeffects here AFAIK), and this one seems to work for many viewers and zoom levels, i.e. some of the things but not all in your code are also viewer issues.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint-hatchthickness-hatchthickness
pgfpathlinetopgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance+hatchthickness-hatchthickness
pgfpathlinetopgfqpoint-hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
You do what one usually does: define the cell size a bit smaller than what the path actually covers. The problem is that if the width of the line exceeds 0.5pt
, an overshoot by 1pt
is no longer sufficient. So one may want to use a more generous overshoot. The following may be a bit "too generous" (but being
generous has no real sideeffects here AFAIK), and this one seems to work for many viewers and zoom levels, i.e. some of the things but not all in your code are also viewer issues.
documentclass[tikz,border=3.14mm]standalone
begindocument
begintikzpicture
usetikzlibrarypatterns
makeatletter
tikzsethatch distance/.store in=hatchdistance,hatch distance=5pt,hatch thickness/.store in=hatchthickness,hatch thickness=5pt
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north east hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpoint-hatchthickness-hatchthickness
pgfpathlinetopgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
pgfdeclarepatternformonly[hatchdistance,hatchthickness]north west hatch% name
pgfqpoint-hatchthickness-hatchthickness% below left
pgfqpointhatchdistance+hatchthicknesshatchdistance+hatchthickness% above right
pgfpointhatchdistancehatchdistance%
pgfsetcolortikz@pattern@color
pgfsetlinewidthhatchthickness
pgfpathmovetopgfqpointhatchdistance+hatchthickness-hatchthickness
pgfpathlinetopgfqpoint-hatchthicknesshatchdistance+hatchthickness
pgfusepathstroke
makeatother
draw[pattern=north east hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (0,0) rectangle +(1,1);
draw[pattern=north west hatch,hatch distance=7pt,hatch thickness=3pt,pattern color=orange] (2,0) rectangle +(1,1);
endtikzpicture
enddocument
edited 2 hours ago
answered 8 hours ago
marmotmarmot
141k6 gold badges184 silver badges338 bronze badges
141k6 gold badges184 silver badges338 bronze badges
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
add a comment |
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
When I use your solution I get teeth, even bigger ones, on the other side?!
– Pygmalion
5 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
@Pygmalion Hmmh, strange. I slightly adjusted the parameters. Is it better now?
– marmot
2 hours ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f498376%2fcreating-patterns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown