draw on image not fit original one perfectly
up vote
7
down vote
favorite
Say I draw a red image with below code, generate input.pdf:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt,red]
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
Then include input.pdf and draw the same thing on this image (draw with black):
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (0,0) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
But the black line not over red line perfectly,see below zoomed parts:
What's wrong with my draw on image code?
tikz-pgf
add a comment |
up vote
7
down vote
favorite
Say I draw a red image with below code, generate input.pdf:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt,red]
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
Then include input.pdf and draw the same thing on this image (draw with black):
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (0,0) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
But the black line not over red line perfectly,see below zoomed parts:
What's wrong with my draw on image code?
tikz-pgf
3
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
I think the problem is thedraw
. Replace it byfill[yellow]
andfill[green]
for exmple.
– Sigur
yesterday
1
@marmot is right. put your node at(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.
– David Purton
yesterday
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
Say I draw a red image with below code, generate input.pdf:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt,red]
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
Then include input.pdf and draw the same thing on this image (draw with black):
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (0,0) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
But the black line not over red line perfectly,see below zoomed parts:
What's wrong with my draw on image code?
tikz-pgf
Say I draw a red image with below code, generate input.pdf:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt,red]
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
Then include input.pdf and draw the same thing on this image (draw with black):
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (0,0) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
But the black line not over red line perfectly,see below zoomed parts:
What's wrong with my draw on image code?
tikz-pgf
tikz-pgf
asked yesterday
lucky1928
9831614
9831614
3
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
I think the problem is thedraw
. Replace it byfill[yellow]
andfill[green]
for exmple.
– Sigur
yesterday
1
@marmot is right. put your node at(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.
– David Purton
yesterday
add a comment |
3
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
I think the problem is thedraw
. Replace it byfill[yellow]
andfill[green]
for exmple.
– Sigur
yesterday
1
@marmot is right. put your node at(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.
– David Purton
yesterday
3
3
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
I think the problem is the
draw
. Replace it by fill[yellow]
and fill[green]
for exmple.– Sigur
yesterday
I think the problem is the
draw
. Replace it by fill[yellow]
and fill[green]
for exmple.– Sigur
yesterday
1
1
@marmot is right. put your node at
(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.– David Purton
yesterday
@marmot is right. put your node at
(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.– David Purton
yesterday
add a comment |
2 Answers
2
active
oldest
votes
up vote
10
down vote
accepted
OK, I just tried what I thought should work, and surprisingly it does. That is.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (-pgflinewidth/2,-pgflinewidth/2) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
produces
as expected. Why? You put the node with anchor south west
, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)
add a comment |
up vote
3
down vote
An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[inner sep=0,outer sep=0] at (25,25) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
OK, I just tried what I thought should work, and surprisingly it does. That is.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (-pgflinewidth/2,-pgflinewidth/2) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
produces
as expected. Why? You put the node with anchor south west
, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)
add a comment |
up vote
10
down vote
accepted
OK, I just tried what I thought should work, and surprisingly it does. That is.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (-pgflinewidth/2,-pgflinewidth/2) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
produces
as expected. Why? You put the node with anchor south west
, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)
add a comment |
up vote
10
down vote
accepted
up vote
10
down vote
accepted
OK, I just tried what I thought should work, and surprisingly it does. That is.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (-pgflinewidth/2,-pgflinewidth/2) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
produces
as expected. Why? You put the node with anchor south west
, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)
OK, I just tried what I thought should work, and surprisingly it does. That is.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[anchor=south west,inner sep=0,outer sep=0] at (-pgflinewidth/2,-pgflinewidth/2) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
produces
as expected. Why? You put the node with anchor south west
, and, as pointed out
by David Purton, your image is wider (and taller) by the line width (since it is wider and taller by half the line width in each direction). And why is this? You draw a path through the specified coordinates, and the line width gets added to this. I know that the explanation is very clumsy, it would be much easier in marmot language, but I am not sure how to type this, so as a compromise I add a figure. ;-)
answered yesterday
marmot
76.7k487161
76.7k487161
add a comment |
add a comment |
up vote
3
down vote
An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[inner sep=0,outer sep=0] at (25,25) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
add a comment |
up vote
3
down vote
An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[inner sep=0,outer sep=0] at (25,25) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
add a comment |
up vote
3
down vote
up vote
3
down vote
An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[inner sep=0,outer sep=0] at (25,25) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
An alternative to @marmot's solution is to put the image at (25,25) to line up with your circle and anchor it at it's centre:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[x=1pt,y=1pt,line width = 1pt]
node[inner sep=0,outer sep=0] at (25,25) {includegraphics{input.pdf}};
draw (0,0) rectangle (50,50);
draw (25,25) circle (25);
end{tikzpicture}
end{document}
answered yesterday
David Purton
8,2641834
8,2641834
add a comment |
add a comment |
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%2f460864%2fdraw-on-image-not-fit-original-one-perfectly%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
3
Well, seems like you did not take into account the line width. Try putting the image at (-pgflinewidth/2,-pgflinewidth/2) to take this into account.
– marmot
yesterday
I think the problem is the
draw
. Replace it byfill[yellow]
andfill[green]
for exmple.– Sigur
yesterday
1
@marmot is right. put your node at
(-0.5,-0.5)
(half line width offset) and it lines up right. Your image is actually 51pt × 51pt but your code assumes it is 50pt × 50pt.– David Purton
yesterday