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
Show that there are infinitely more problems than we will ever be able to compute
How can solar sailed ships be protected from space debris?
CPA filed late returns, stating I would get money; IRS says they were filed too late
What is the maximum amount of diamond in one Minecraft game?
Park the computer
Why would "dead languages" be the only languages that spells could be written in?
Can 4 Joy cons connect to the same Switch?
How serious is plagiarism in a master’s thesis?
How can power levels matter in a magic system that emphasizes control?
How to travel between two stationary worlds in the least amount of time? (time dilation)
how can i make this execution plan more efficient?
PhD: When to quit and move on?
Do I need to be legally qualified to install a Hive smart thermostat?
How can I define a very large matrix efficiently?
Does Evolution Sage proliferate Blast Zone when played?
Why did moving the mouse cursor cause Windows 95 to run more quickly?
How many spells does my Bard 6/Wizard 1 know?
What is the difference between a historical drama and a period drama?
What is this arch-and-tower near a road?
How to calculate a conditional PDF in mathematica?
Speeding up thousands of string parses
Has chattel slavery ever been used as a criminal punishment in the USA since the passage of the Thirteenth Amendment?
How should I present a resort brochure in my general fiction?
Has there ever been a cold war other than between the U.S. and the U.S.S.R.?
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