Draw ruler grid on image node by cm unit
up vote
0
down vote
favorite
I try to draw a grid on image with cm unit. I know many solution for this topic. My idea right now is try to calculate it as below! I guess should use n1 and n2 as foreach up limit (currently use width and height macro).
documentclass[border=2mm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,calc}
begin{document}
begin{tikzpicture}
defwidth{6}
defheight{8}
%tikzstyle{every node}=[ultra thick, draw]
node[anchor=south west,opacity=0.5,inner sep=0] (image) at (0,0) {includegraphics[width=0.9textwidth]{example-image-a}};
draw[line width=2pt]
let
p1=(image.south west),
p2=(image.north east),
n1={(x2-x1)},
n2={(y2-y1)}
in node[anchor=west] at (0,-2) {Huge n1,n2}
foreach col in {0,...,height} {
foreach row in {0,...,width} {
(0,col) -- (width,col)
(row,0) -- (row,height)
}}
foreach x in {0,1,...,width} {node[anchor=north] at (x,0) {x}}
foreach y in {0,1,...,height} {node[anchor=east] at (0,y) {y}}
;
end{tikzpicture}
end{document}
Currently the unit of n1 and n2 is pt, maybe I need to convert it to cm unit but I don't how to do it.
My target is use n1 and n2 as the foreach up limit instead of width and height. so it will match the image exactly!

tikz-pgf
add a comment |
up vote
0
down vote
favorite
I try to draw a grid on image with cm unit. I know many solution for this topic. My idea right now is try to calculate it as below! I guess should use n1 and n2 as foreach up limit (currently use width and height macro).
documentclass[border=2mm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,calc}
begin{document}
begin{tikzpicture}
defwidth{6}
defheight{8}
%tikzstyle{every node}=[ultra thick, draw]
node[anchor=south west,opacity=0.5,inner sep=0] (image) at (0,0) {includegraphics[width=0.9textwidth]{example-image-a}};
draw[line width=2pt]
let
p1=(image.south west),
p2=(image.north east),
n1={(x2-x1)},
n2={(y2-y1)}
in node[anchor=west] at (0,-2) {Huge n1,n2}
foreach col in {0,...,height} {
foreach row in {0,...,width} {
(0,col) -- (width,col)
(row,0) -- (row,height)
}}
foreach x in {0,1,...,width} {node[anchor=north] at (x,0) {x}}
foreach y in {0,1,...,height} {node[anchor=east] at (0,y) {y}}
;
end{tikzpicture}
end{document}
Currently the unit of n1 and n2 is pt, maybe I need to convert it to cm unit but I don't how to do it.
My target is use n1 and n2 as the foreach up limit instead of width and height. so it will match the image exactly!

tikz-pgf
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to draw a grid on image with cm unit. I know many solution for this topic. My idea right now is try to calculate it as below! I guess should use n1 and n2 as foreach up limit (currently use width and height macro).
documentclass[border=2mm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,calc}
begin{document}
begin{tikzpicture}
defwidth{6}
defheight{8}
%tikzstyle{every node}=[ultra thick, draw]
node[anchor=south west,opacity=0.5,inner sep=0] (image) at (0,0) {includegraphics[width=0.9textwidth]{example-image-a}};
draw[line width=2pt]
let
p1=(image.south west),
p2=(image.north east),
n1={(x2-x1)},
n2={(y2-y1)}
in node[anchor=west] at (0,-2) {Huge n1,n2}
foreach col in {0,...,height} {
foreach row in {0,...,width} {
(0,col) -- (width,col)
(row,0) -- (row,height)
}}
foreach x in {0,1,...,width} {node[anchor=north] at (x,0) {x}}
foreach y in {0,1,...,height} {node[anchor=east] at (0,y) {y}}
;
end{tikzpicture}
end{document}
Currently the unit of n1 and n2 is pt, maybe I need to convert it to cm unit but I don't how to do it.
My target is use n1 and n2 as the foreach up limit instead of width and height. so it will match the image exactly!

tikz-pgf
I try to draw a grid on image with cm unit. I know many solution for this topic. My idea right now is try to calculate it as below! I guess should use n1 and n2 as foreach up limit (currently use width and height macro).
documentclass[border=2mm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,calc}
begin{document}
begin{tikzpicture}
defwidth{6}
defheight{8}
%tikzstyle{every node}=[ultra thick, draw]
node[anchor=south west,opacity=0.5,inner sep=0] (image) at (0,0) {includegraphics[width=0.9textwidth]{example-image-a}};
draw[line width=2pt]
let
p1=(image.south west),
p2=(image.north east),
n1={(x2-x1)},
n2={(y2-y1)}
in node[anchor=west] at (0,-2) {Huge n1,n2}
foreach col in {0,...,height} {
foreach row in {0,...,width} {
(0,col) -- (width,col)
(row,0) -- (row,height)
}}
foreach x in {0,1,...,width} {node[anchor=north] at (x,0) {x}}
foreach y in {0,1,...,height} {node[anchor=east] at (0,y) {y}}
;
end{tikzpicture}
end{document}
Currently the unit of n1 and n2 is pt, maybe I need to convert it to cm unit but I don't how to do it.
My target is use n1 and n2 as the foreach up limit instead of width and height. so it will match the image exactly!

tikz-pgf
tikz-pgf
asked 2 mins ago
beetlej
51629
51629
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f463251%2fdraw-ruler-grid-on-image-node-by-cm-unit%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