pattern=grid, how to simple increase grid steps
i have the following mwe:
documentclass[tikz, margin=3]{standalone}
usetikzlibrary{patterns}
begin{document}
begin{tikzpicture}[pattern color=gray!50]
node (s) [draw=gray!50, thick,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] {some content};
end{tikzpicture}
end{document}
does exist simple way to increase grid steps for grid pattern? for example that distances between lines are 5mm and lines are very thin
? or should i define new grid pattern? if this is only solution, please can someone show me how to do this? i look to changing-density-of-pattern, but i'm not able to accommodate this solution to grids.
tikz-node pattern
add a comment |
i have the following mwe:
documentclass[tikz, margin=3]{standalone}
usetikzlibrary{patterns}
begin{document}
begin{tikzpicture}[pattern color=gray!50]
node (s) [draw=gray!50, thick,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] {some content};
end{tikzpicture}
end{document}
does exist simple way to increase grid steps for grid pattern? for example that distances between lines are 5mm and lines are very thin
? or should i define new grid pattern? if this is only solution, please can someone show me how to do this? i look to changing-density-of-pattern, but i'm not able to accommodate this solution to grids.
tikz-node pattern
add a comment |
i have the following mwe:
documentclass[tikz, margin=3]{standalone}
usetikzlibrary{patterns}
begin{document}
begin{tikzpicture}[pattern color=gray!50]
node (s) [draw=gray!50, thick,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] {some content};
end{tikzpicture}
end{document}
does exist simple way to increase grid steps for grid pattern? for example that distances between lines are 5mm and lines are very thin
? or should i define new grid pattern? if this is only solution, please can someone show me how to do this? i look to changing-density-of-pattern, but i'm not able to accommodate this solution to grids.
tikz-node pattern
i have the following mwe:
documentclass[tikz, margin=3]{standalone}
usetikzlibrary{patterns}
begin{document}
begin{tikzpicture}[pattern color=gray!50]
node (s) [draw=gray!50, thick,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] {some content};
end{tikzpicture}
end{document}
does exist simple way to increase grid steps for grid pattern? for example that distances between lines are 5mm and lines are very thin
? or should i define new grid pattern? if this is only solution, please can someone show me how to do this? i look to changing-density-of-pattern, but i'm not able to accommodate this solution to grids.
tikz-node pattern
tikz-node pattern
asked Feb 9 at 23:03
ZarkoZarko
124k866164
124k866164
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
From your comments I understand that you want a grid that moves with the node or some other path. This can be easily obtained with a path picture.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{calc}
pgfkeys{/Zarko/.cd,
grid/.style={draw=gray!50,thin},
x distance/.initial=8mm,
y distance/.initial=8mm,
distance/.code={pgfkeys{/Zarko/x distance=#1,/Zarko/y distance=#1}}
}
tikzset{Zarko grid/.style={/utils/exec=pgfkeys{/Zarko/.cd,#1},
path picture={
path[/Zarko/grid] let p1=($(path picture bounding box.north east)-(path picture bounding
box.south west)$),n1={int(x1/pgfkeysvalueof{/Zarko/x distance})},
n2={int(y1/pgfkeysvalueof{/Zarko/y distance})} in
foreach XX in {1,...,n1}
{
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.south west)
--
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.north west)
}
foreach YY in {1,...,n2} {
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south west)
--
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south east)
};
}}}
begin{document}
begin{tikzpicture}
node (s) [Zarko grid,draw=gray!50, thick,
minimum width=30mm, minimum height=20mm] {some content};
node (s') [Zarko grid={distance=3mm},draw=gray!50, thick,
minimum width=30mm, minimum height=24mm] at (0,-4) {some content};
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
end{tikzpicture}
end{document}
One could make it more flexible by adding some x offset
and y offset
but I guess you will be able to do that when needed.
As for "honest-to-god" grids: I copied my old answer and it seems to work. (I only had to add the color to the options of the grid, no idea why I didn't do that in the original answer.) EDIT: I cleaned my code, when I wrote the answer I didn't know, for instance, that the calc package (not library) redefines setlength
etc. So I hope to have made my code a bit less dangerous.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{patterns}
makeatletter
newlength{flex@pattern@density}
newlength{flex@pattern@linewidth}
newlength{flex@pattern@auxlength}
newlength{flex@pattern@auxlengthtwo}
tikzset{/tikz/.cd,
pattern density/.code={flex@pattern@density=#1
flex@pattern@auxlength=1.1flex@pattern@density
flex@pattern@auxlengthtwo=flex@pattern@density
advanceflex@pattern@auxlengthtwo by 0.1pt
%typeout{theflex@pattern@density,theflex@pattern@auxlength}
},
pattern density=3pt,
pattern line width/.code={flex@pattern@linewidth=#1},
pattern line width=0.4pt,
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible horizontal lines}{pgfpointorigin}{pgfqpoint{100pt}{1pt}}{pgfqpoint{100pt}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0.5pt}}
pgfpathlineto{pgfqpoint{100pt}{0.5pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible vertical lines}{pgfpointorigin}{pgfqpoint{1pt}{100pt}}{pgfqpoint{flex@pattern@density}{100pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0.5pt}{0pt}}
pgfpathlineto{pgfqpoint{0.5pt}{100pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north east lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@auxlengthtwo}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north west lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@auxlengthtwo}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
% Crossed lines in different directions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible grid}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{0pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible crosshatch}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{3pt}{3pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@density}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{flex@pattern@density}}
pgfusepath{stroke}
}
% Dotted regions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible crosshatch dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{2.5pt}{2.5pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfpathcircle{pgfqpoint{1.5pt}{1.5pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
makeatother
begin{document}
begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw[very thick,
pattern=flexible grid,pattern line
width=0.4pt,pattern color=blue,
pattern density=5mm] (0,5) -- (0,0) -- (5,0) -- (5,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (7,0) {some content};
end{scope}
end{tikzpicture}
end{document}
ADDENDUM: If I use the same preamble for
begin{document}
foreach X in {2,2.033,...,4,3.967,...,2}
{begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw (0,-3) rectangle (8,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{sin(X*90)}) {some content};
node (s') [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{3+sin(X*90)}) {some content};
end{scope}
end{tikzpicture}}
end{document}
I get this "beautiful" animation:
It shows that the patterns are, in principle, equally in hitting the boundary of the node, it is only that the finer pattern has statistically a better chance of doing so, but other than that the patterns are on the same footing.
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters toZarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).
– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness togrid/.style
.
– marmot
Feb 11 at 14:40
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%2f474124%2fpattern-grid-how-to-simple-increase-grid-steps%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From your comments I understand that you want a grid that moves with the node or some other path. This can be easily obtained with a path picture.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{calc}
pgfkeys{/Zarko/.cd,
grid/.style={draw=gray!50,thin},
x distance/.initial=8mm,
y distance/.initial=8mm,
distance/.code={pgfkeys{/Zarko/x distance=#1,/Zarko/y distance=#1}}
}
tikzset{Zarko grid/.style={/utils/exec=pgfkeys{/Zarko/.cd,#1},
path picture={
path[/Zarko/grid] let p1=($(path picture bounding box.north east)-(path picture bounding
box.south west)$),n1={int(x1/pgfkeysvalueof{/Zarko/x distance})},
n2={int(y1/pgfkeysvalueof{/Zarko/y distance})} in
foreach XX in {1,...,n1}
{
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.south west)
--
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.north west)
}
foreach YY in {1,...,n2} {
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south west)
--
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south east)
};
}}}
begin{document}
begin{tikzpicture}
node (s) [Zarko grid,draw=gray!50, thick,
minimum width=30mm, minimum height=20mm] {some content};
node (s') [Zarko grid={distance=3mm},draw=gray!50, thick,
minimum width=30mm, minimum height=24mm] at (0,-4) {some content};
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
end{tikzpicture}
end{document}
One could make it more flexible by adding some x offset
and y offset
but I guess you will be able to do that when needed.
As for "honest-to-god" grids: I copied my old answer and it seems to work. (I only had to add the color to the options of the grid, no idea why I didn't do that in the original answer.) EDIT: I cleaned my code, when I wrote the answer I didn't know, for instance, that the calc package (not library) redefines setlength
etc. So I hope to have made my code a bit less dangerous.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{patterns}
makeatletter
newlength{flex@pattern@density}
newlength{flex@pattern@linewidth}
newlength{flex@pattern@auxlength}
newlength{flex@pattern@auxlengthtwo}
tikzset{/tikz/.cd,
pattern density/.code={flex@pattern@density=#1
flex@pattern@auxlength=1.1flex@pattern@density
flex@pattern@auxlengthtwo=flex@pattern@density
advanceflex@pattern@auxlengthtwo by 0.1pt
%typeout{theflex@pattern@density,theflex@pattern@auxlength}
},
pattern density=3pt,
pattern line width/.code={flex@pattern@linewidth=#1},
pattern line width=0.4pt,
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible horizontal lines}{pgfpointorigin}{pgfqpoint{100pt}{1pt}}{pgfqpoint{100pt}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0.5pt}}
pgfpathlineto{pgfqpoint{100pt}{0.5pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible vertical lines}{pgfpointorigin}{pgfqpoint{1pt}{100pt}}{pgfqpoint{flex@pattern@density}{100pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0.5pt}{0pt}}
pgfpathlineto{pgfqpoint{0.5pt}{100pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north east lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@auxlengthtwo}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north west lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@auxlengthtwo}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
% Crossed lines in different directions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible grid}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{0pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible crosshatch}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{3pt}{3pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@density}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{flex@pattern@density}}
pgfusepath{stroke}
}
% Dotted regions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible crosshatch dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{2.5pt}{2.5pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfpathcircle{pgfqpoint{1.5pt}{1.5pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
makeatother
begin{document}
begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw[very thick,
pattern=flexible grid,pattern line
width=0.4pt,pattern color=blue,
pattern density=5mm] (0,5) -- (0,0) -- (5,0) -- (5,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (7,0) {some content};
end{scope}
end{tikzpicture}
end{document}
ADDENDUM: If I use the same preamble for
begin{document}
foreach X in {2,2.033,...,4,3.967,...,2}
{begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw (0,-3) rectangle (8,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{sin(X*90)}) {some content};
node (s') [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{3+sin(X*90)}) {some content};
end{scope}
end{tikzpicture}}
end{document}
I get this "beautiful" animation:
It shows that the patterns are, in principle, equally in hitting the boundary of the node, it is only that the finer pattern has statistically a better chance of doing so, but other than that the patterns are on the same footing.
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters toZarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).
– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness togrid/.style
.
– marmot
Feb 11 at 14:40
add a comment |
From your comments I understand that you want a grid that moves with the node or some other path. This can be easily obtained with a path picture.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{calc}
pgfkeys{/Zarko/.cd,
grid/.style={draw=gray!50,thin},
x distance/.initial=8mm,
y distance/.initial=8mm,
distance/.code={pgfkeys{/Zarko/x distance=#1,/Zarko/y distance=#1}}
}
tikzset{Zarko grid/.style={/utils/exec=pgfkeys{/Zarko/.cd,#1},
path picture={
path[/Zarko/grid] let p1=($(path picture bounding box.north east)-(path picture bounding
box.south west)$),n1={int(x1/pgfkeysvalueof{/Zarko/x distance})},
n2={int(y1/pgfkeysvalueof{/Zarko/y distance})} in
foreach XX in {1,...,n1}
{
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.south west)
--
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.north west)
}
foreach YY in {1,...,n2} {
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south west)
--
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south east)
};
}}}
begin{document}
begin{tikzpicture}
node (s) [Zarko grid,draw=gray!50, thick,
minimum width=30mm, minimum height=20mm] {some content};
node (s') [Zarko grid={distance=3mm},draw=gray!50, thick,
minimum width=30mm, minimum height=24mm] at (0,-4) {some content};
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
end{tikzpicture}
end{document}
One could make it more flexible by adding some x offset
and y offset
but I guess you will be able to do that when needed.
As for "honest-to-god" grids: I copied my old answer and it seems to work. (I only had to add the color to the options of the grid, no idea why I didn't do that in the original answer.) EDIT: I cleaned my code, when I wrote the answer I didn't know, for instance, that the calc package (not library) redefines setlength
etc. So I hope to have made my code a bit less dangerous.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{patterns}
makeatletter
newlength{flex@pattern@density}
newlength{flex@pattern@linewidth}
newlength{flex@pattern@auxlength}
newlength{flex@pattern@auxlengthtwo}
tikzset{/tikz/.cd,
pattern density/.code={flex@pattern@density=#1
flex@pattern@auxlength=1.1flex@pattern@density
flex@pattern@auxlengthtwo=flex@pattern@density
advanceflex@pattern@auxlengthtwo by 0.1pt
%typeout{theflex@pattern@density,theflex@pattern@auxlength}
},
pattern density=3pt,
pattern line width/.code={flex@pattern@linewidth=#1},
pattern line width=0.4pt,
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible horizontal lines}{pgfpointorigin}{pgfqpoint{100pt}{1pt}}{pgfqpoint{100pt}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0.5pt}}
pgfpathlineto{pgfqpoint{100pt}{0.5pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible vertical lines}{pgfpointorigin}{pgfqpoint{1pt}{100pt}}{pgfqpoint{flex@pattern@density}{100pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0.5pt}{0pt}}
pgfpathlineto{pgfqpoint{0.5pt}{100pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north east lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@auxlengthtwo}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north west lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@auxlengthtwo}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
% Crossed lines in different directions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible grid}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{0pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible crosshatch}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{3pt}{3pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@density}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{flex@pattern@density}}
pgfusepath{stroke}
}
% Dotted regions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible crosshatch dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{2.5pt}{2.5pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfpathcircle{pgfqpoint{1.5pt}{1.5pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
makeatother
begin{document}
begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw[very thick,
pattern=flexible grid,pattern line
width=0.4pt,pattern color=blue,
pattern density=5mm] (0,5) -- (0,0) -- (5,0) -- (5,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (7,0) {some content};
end{scope}
end{tikzpicture}
end{document}
ADDENDUM: If I use the same preamble for
begin{document}
foreach X in {2,2.033,...,4,3.967,...,2}
{begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw (0,-3) rectangle (8,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{sin(X*90)}) {some content};
node (s') [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{3+sin(X*90)}) {some content};
end{scope}
end{tikzpicture}}
end{document}
I get this "beautiful" animation:
It shows that the patterns are, in principle, equally in hitting the boundary of the node, it is only that the finer pattern has statistically a better chance of doing so, but other than that the patterns are on the same footing.
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters toZarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).
– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness togrid/.style
.
– marmot
Feb 11 at 14:40
add a comment |
From your comments I understand that you want a grid that moves with the node or some other path. This can be easily obtained with a path picture.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{calc}
pgfkeys{/Zarko/.cd,
grid/.style={draw=gray!50,thin},
x distance/.initial=8mm,
y distance/.initial=8mm,
distance/.code={pgfkeys{/Zarko/x distance=#1,/Zarko/y distance=#1}}
}
tikzset{Zarko grid/.style={/utils/exec=pgfkeys{/Zarko/.cd,#1},
path picture={
path[/Zarko/grid] let p1=($(path picture bounding box.north east)-(path picture bounding
box.south west)$),n1={int(x1/pgfkeysvalueof{/Zarko/x distance})},
n2={int(y1/pgfkeysvalueof{/Zarko/y distance})} in
foreach XX in {1,...,n1}
{
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.south west)
--
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.north west)
}
foreach YY in {1,...,n2} {
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south west)
--
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south east)
};
}}}
begin{document}
begin{tikzpicture}
node (s) [Zarko grid,draw=gray!50, thick,
minimum width=30mm, minimum height=20mm] {some content};
node (s') [Zarko grid={distance=3mm},draw=gray!50, thick,
minimum width=30mm, minimum height=24mm] at (0,-4) {some content};
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
end{tikzpicture}
end{document}
One could make it more flexible by adding some x offset
and y offset
but I guess you will be able to do that when needed.
As for "honest-to-god" grids: I copied my old answer and it seems to work. (I only had to add the color to the options of the grid, no idea why I didn't do that in the original answer.) EDIT: I cleaned my code, when I wrote the answer I didn't know, for instance, that the calc package (not library) redefines setlength
etc. So I hope to have made my code a bit less dangerous.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{patterns}
makeatletter
newlength{flex@pattern@density}
newlength{flex@pattern@linewidth}
newlength{flex@pattern@auxlength}
newlength{flex@pattern@auxlengthtwo}
tikzset{/tikz/.cd,
pattern density/.code={flex@pattern@density=#1
flex@pattern@auxlength=1.1flex@pattern@density
flex@pattern@auxlengthtwo=flex@pattern@density
advanceflex@pattern@auxlengthtwo by 0.1pt
%typeout{theflex@pattern@density,theflex@pattern@auxlength}
},
pattern density=3pt,
pattern line width/.code={flex@pattern@linewidth=#1},
pattern line width=0.4pt,
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible horizontal lines}{pgfpointorigin}{pgfqpoint{100pt}{1pt}}{pgfqpoint{100pt}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0.5pt}}
pgfpathlineto{pgfqpoint{100pt}{0.5pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible vertical lines}{pgfpointorigin}{pgfqpoint{1pt}{100pt}}{pgfqpoint{flex@pattern@density}{100pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0.5pt}{0pt}}
pgfpathlineto{pgfqpoint{0.5pt}{100pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north east lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@auxlengthtwo}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north west lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@auxlengthtwo}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
% Crossed lines in different directions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible grid}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{0pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible crosshatch}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{3pt}{3pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@density}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{flex@pattern@density}}
pgfusepath{stroke}
}
% Dotted regions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible crosshatch dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{2.5pt}{2.5pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfpathcircle{pgfqpoint{1.5pt}{1.5pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
makeatother
begin{document}
begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw[very thick,
pattern=flexible grid,pattern line
width=0.4pt,pattern color=blue,
pattern density=5mm] (0,5) -- (0,0) -- (5,0) -- (5,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (7,0) {some content};
end{scope}
end{tikzpicture}
end{document}
ADDENDUM: If I use the same preamble for
begin{document}
foreach X in {2,2.033,...,4,3.967,...,2}
{begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw (0,-3) rectangle (8,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{sin(X*90)}) {some content};
node (s') [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{3+sin(X*90)}) {some content};
end{scope}
end{tikzpicture}}
end{document}
I get this "beautiful" animation:
It shows that the patterns are, in principle, equally in hitting the boundary of the node, it is only that the finer pattern has statistically a better chance of doing so, but other than that the patterns are on the same footing.
From your comments I understand that you want a grid that moves with the node or some other path. This can be easily obtained with a path picture.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{calc}
pgfkeys{/Zarko/.cd,
grid/.style={draw=gray!50,thin},
x distance/.initial=8mm,
y distance/.initial=8mm,
distance/.code={pgfkeys{/Zarko/x distance=#1,/Zarko/y distance=#1}}
}
tikzset{Zarko grid/.style={/utils/exec=pgfkeys{/Zarko/.cd,#1},
path picture={
path[/Zarko/grid] let p1=($(path picture bounding box.north east)-(path picture bounding
box.south west)$),n1={int(x1/pgfkeysvalueof{/Zarko/x distance})},
n2={int(y1/pgfkeysvalueof{/Zarko/y distance})} in
foreach XX in {1,...,n1}
{
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.south west)
--
([xshift=XX*pgfkeysvalueof{/Zarko/x distance}]path picture bounding box.north west)
}
foreach YY in {1,...,n2} {
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south west)
--
([yshift=YY*pgfkeysvalueof{/Zarko/y distance}]path picture bounding box.south east)
};
}}}
begin{document}
begin{tikzpicture}
node (s) [Zarko grid,draw=gray!50, thick,
minimum width=30mm, minimum height=20mm] {some content};
node (s') [Zarko grid={distance=3mm},draw=gray!50, thick,
minimum width=30mm, minimum height=24mm] at (0,-4) {some content};
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
end{tikzpicture}
end{document}
One could make it more flexible by adding some x offset
and y offset
but I guess you will be able to do that when needed.
As for "honest-to-god" grids: I copied my old answer and it seems to work. (I only had to add the color to the options of the grid, no idea why I didn't do that in the original answer.) EDIT: I cleaned my code, when I wrote the answer I didn't know, for instance, that the calc package (not library) redefines setlength
etc. So I hope to have made my code a bit less dangerous.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{patterns}
makeatletter
newlength{flex@pattern@density}
newlength{flex@pattern@linewidth}
newlength{flex@pattern@auxlength}
newlength{flex@pattern@auxlengthtwo}
tikzset{/tikz/.cd,
pattern density/.code={flex@pattern@density=#1
flex@pattern@auxlength=1.1flex@pattern@density
flex@pattern@auxlengthtwo=flex@pattern@density
advanceflex@pattern@auxlengthtwo by 0.1pt
%typeout{theflex@pattern@density,theflex@pattern@auxlength}
},
pattern density=3pt,
pattern line width/.code={flex@pattern@linewidth=#1},
pattern line width=0.4pt,
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible horizontal lines}{pgfpointorigin}{pgfqpoint{100pt}{1pt}}{pgfqpoint{100pt}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0.5pt}}
pgfpathlineto{pgfqpoint{100pt}{0.5pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible vertical lines}{pgfpointorigin}{pgfqpoint{1pt}{100pt}}{pgfqpoint{flex@pattern@density}{100pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0.5pt}{0pt}}
pgfpathlineto{pgfqpoint{0.5pt}{100pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north east lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@auxlengthtwo}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@auxlengthtwo,flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible north west lines}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@auxlengthtwo}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@auxlengthtwo}}
pgfusepath{stroke}
}
% Crossed lines in different directions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible grid}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{0pt}}
pgfusepath{stroke}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,flex@pattern@auxlength,tikz@pattern@color]{flexible crosshatch}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{flex@pattern@auxlength}{flex@pattern@auxlength}}{pgfqpoint{3pt}{3pt}}%
{
pgfsetlinewidth{flex@pattern@linewidth}
pgfsetcolor{tikz@pattern@color}
pgfpathmoveto{pgfqpoint{flex@pattern@density}{0pt}}
pgfpathlineto{pgfqpoint{0pt}{flex@pattern@density}}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{flex@pattern@density}{flex@pattern@density}}
pgfusepath{stroke}
}
% Dotted regions
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
pgfdeclarepatternformonly[flex@pattern@density,flex@pattern@linewidth,tikz@pattern@color]{flexible crosshatch dots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{2.5pt}{2.5pt}}{pgfqpoint{flex@pattern@density}{flex@pattern@density}}%
{
pgfsetcolor{tikz@pattern@color}
pgfpathcircle{pgfqpoint{0pt}{0pt}}{flex@pattern@linewidth}
pgfpathcircle{pgfqpoint{1.5pt}{1.5pt}}{flex@pattern@linewidth}
pgfusepath{fill}
}
makeatother
begin{document}
begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw[very thick,
pattern=flexible grid,pattern line
width=0.4pt,pattern color=blue,
pattern density=5mm] (0,5) -- (0,0) -- (5,0) -- (5,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (7,0) {some content};
end{scope}
end{tikzpicture}
end{document}
ADDENDUM: If I use the same preamble for
begin{document}
foreach X in {2,2.033,...,4,3.967,...,2}
{begin{tikzpicture}[>=stealth,every node/.style={font=tiny}]
draw (0,-3) rectangle (8,5);
begin{scope}[pattern density=5mm,pattern line
width=0.4pt]
node (s) [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=flexible grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{sin(X*90)}) {some content};
node (s') [draw=gray!50, thick,pattern color=gray!50,
preaction={pattern=grid},
minimum width=30mm, minimum height=20mm,
below right] at (X,{3+sin(X*90)}) {some content};
end{scope}
end{tikzpicture}}
end{document}
I get this "beautiful" animation:
It shows that the patterns are, in principle, equally in hitting the boundary of the node, it is only that the finer pattern has statistically a better chance of doing so, but other than that the patterns are on the same footing.
edited Feb 10 at 2:23
answered Feb 9 at 23:32
marmotmarmot
101k4116223
101k4116223
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters toZarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).
– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness togrid/.style
.
– marmot
Feb 11 at 14:40
add a comment |
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters toZarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).
– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness togrid/.style
.
– marmot
Feb 11 at 14:40
1
1
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
huh, as i afraid, it seems that for my problem is not simpler solution :-( . thank you very much (+1, for accepting I'll wait a while).
– Zarko
Feb 10 at 0:17
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
so far i stick with drawing grid over node starting in one corner and end in diagonal opposite one. however, it almost newer start with line but as you show in the example. interestingly, if i use standard grid pattern, it always start with (border) line, but with your definition this is lost. thank editing of your answer.
– Zarko
Feb 10 at 0:38
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
@Zarko I added an animation. And I believe that you only have a statistical effect: the finer pattern has a better chance of coinciding with the boundary of the node, but there is no difference in principle.
– marmot
Feb 10 at 1:07
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters to
Zarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).– Zarko
Feb 11 at 10:16
thank you very much for animation :-). meanwhile i try to learn how your code works. i made some progress but not sufficient, that i was able to introduce more parameters to
Zarko grid={...}
. for example, i like to add grid color (change default choice here) and thickness of lines (also possible change default value).– Zarko
Feb 11 at 10:16
@Zarko In the examples, these things are all done.
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness to grid/.style
.– marmot
Feb 11 at 14:40
@Zarko In the examples, these things are all done.
draw[blue,Zarko grid={x distance=4mm,y distance=2mm,grid/.style={draw=red}}] (4,0) --(6,3) -- (5,-2) -- cycle;
You can add your thickness to grid/.style
.– marmot
Feb 11 at 14:40
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%2f474124%2fpattern-grid-how-to-simple-increase-grid-steps%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