How do I remove extra padding from drawing on a figure with tikz?
I am trying to draw over a figure using tikz, using a method for adding scalebars from this answer. The figures that are drawn over this way have extra padding around them (i.e. between the subfigures) that I can't get rid of. Compare the top row of the image below with the bottom row.
I can kind of workaround it by adding an hskip and manually finding the right number for a give figure (see commented out portion of MWE)
documentclass[12pt,a4paper]{article}
usepackage{graphicx}
usepackage{subcaption}
usepackage{tikz}
% Add a scalebar to an image
newcommand{scalebar}[5][white]{%
noindentbegin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [fill=black, fill opacity=0.5] (0.02,0.1cm) rectangle (#4/#3+0.12,1cm);
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.00,0.4cm) node[anchor=south west, font=footnotesize] {{#4}{#5} };
end{scope}
end{tikzpicture} %hskip -1pt % This is my only workaround
}
begin{document}
begin{figure}[h]
centering
begin{subfigure}{textwidth}
caption{}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
begin{subfigure}{textwidth}
caption{}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
end{figure}
end{document}
tikz-pgf floats subcaption
add a comment |
I am trying to draw over a figure using tikz, using a method for adding scalebars from this answer. The figures that are drawn over this way have extra padding around them (i.e. between the subfigures) that I can't get rid of. Compare the top row of the image below with the bottom row.
I can kind of workaround it by adding an hskip and manually finding the right number for a give figure (see commented out portion of MWE)
documentclass[12pt,a4paper]{article}
usepackage{graphicx}
usepackage{subcaption}
usepackage{tikz}
% Add a scalebar to an image
newcommand{scalebar}[5][white]{%
noindentbegin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [fill=black, fill opacity=0.5] (0.02,0.1cm) rectangle (#4/#3+0.12,1cm);
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.00,0.4cm) node[anchor=south west, font=footnotesize] {{#4}{#5} };
end{scope}
end{tikzpicture} %hskip -1pt % This is my only workaround
}
begin{document}
begin{figure}[h]
centering
begin{subfigure}{textwidth}
caption{}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
begin{subfigure}{textwidth}
caption{}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
end{figure}
end{document}
tikz-pgf floats subcaption
1
What happens if you setouter sep=0
?
– marmot
Feb 28 at 0:12
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
You also add space almost every time you end a line with}
instead of}%
.
– John Kormylo
Feb 28 at 5:07
add a comment |
I am trying to draw over a figure using tikz, using a method for adding scalebars from this answer. The figures that are drawn over this way have extra padding around them (i.e. between the subfigures) that I can't get rid of. Compare the top row of the image below with the bottom row.
I can kind of workaround it by adding an hskip and manually finding the right number for a give figure (see commented out portion of MWE)
documentclass[12pt,a4paper]{article}
usepackage{graphicx}
usepackage{subcaption}
usepackage{tikz}
% Add a scalebar to an image
newcommand{scalebar}[5][white]{%
noindentbegin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [fill=black, fill opacity=0.5] (0.02,0.1cm) rectangle (#4/#3+0.12,1cm);
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.00,0.4cm) node[anchor=south west, font=footnotesize] {{#4}{#5} };
end{scope}
end{tikzpicture} %hskip -1pt % This is my only workaround
}
begin{document}
begin{figure}[h]
centering
begin{subfigure}{textwidth}
caption{}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
begin{subfigure}{textwidth}
caption{}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
end{figure}
end{document}
tikz-pgf floats subcaption
I am trying to draw over a figure using tikz, using a method for adding scalebars from this answer. The figures that are drawn over this way have extra padding around them (i.e. between the subfigures) that I can't get rid of. Compare the top row of the image below with the bottom row.
I can kind of workaround it by adding an hskip and manually finding the right number for a give figure (see commented out portion of MWE)
documentclass[12pt,a4paper]{article}
usepackage{graphicx}
usepackage{subcaption}
usepackage{tikz}
% Add a scalebar to an image
newcommand{scalebar}[5][white]{%
noindentbegin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [fill=black, fill opacity=0.5] (0.02,0.1cm) rectangle (#4/#3+0.12,1cm);
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.00,0.4cm) node[anchor=south west, font=footnotesize] {{#4}{#5} };
end{scope}
end{tikzpicture} %hskip -1pt % This is my only workaround
}
begin{document}
begin{figure}[h]
centering
begin{subfigure}{textwidth}
caption{}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
begin{subfigure}{textwidth}
caption{}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
scalebar{includegraphics[width=.3textwidth]{example-image-golden}}{6}{1}{mm}
includegraphics[width=.3textwidth]{example-image-golden}
end{subfigure}
end{figure}
end{document}
tikz-pgf floats subcaption
tikz-pgf floats subcaption
edited Feb 28 at 0:21
argentum2f
asked Feb 28 at 0:08
argentum2fargentum2f
1216
1216
1
What happens if you setouter sep=0
?
– marmot
Feb 28 at 0:12
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
You also add space almost every time you end a line with}
instead of}%
.
– John Kormylo
Feb 28 at 5:07
add a comment |
1
What happens if you setouter sep=0
?
– marmot
Feb 28 at 0:12
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
You also add space almost every time you end a line with}
instead of}%
.
– John Kormylo
Feb 28 at 5:07
1
1
What happens if you set
outer sep=0
?– marmot
Feb 28 at 0:12
What happens if you set
outer sep=0
?– marmot
Feb 28 at 0:12
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
You also add space almost every time you end a line with
}
instead of }%
.– John Kormylo
Feb 28 at 5:07
You also add space almost every time you end a line with
}
instead of }%
.– John Kormylo
Feb 28 at 5:07
add a comment |
1 Answer
1
active
oldest
votes
Ok, I figured this a little after posting. I guess making the MWE simplified it enough I figured out what was wrong.
My defined command had an invisible space in it - that was all that was showing up, I think. See the two spots where I inserted a % at the end of the line:
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
newcommand{scalebar}[5][white]{%
begin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.05,0.4cm) node[anchor=south west] { SI{#4}{#5} };
end{scope}
end{tikzpicture}%
}
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%2f477054%2fhow-do-i-remove-extra-padding-from-drawing-on-a-figure-with-tikz%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
Ok, I figured this a little after posting. I guess making the MWE simplified it enough I figured out what was wrong.
My defined command had an invisible space in it - that was all that was showing up, I think. See the two spots where I inserted a % at the end of the line:
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
newcommand{scalebar}[5][white]{%
begin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.05,0.4cm) node[anchor=south west] { SI{#4}{#5} };
end{scope}
end{tikzpicture}%
}
add a comment |
Ok, I figured this a little after posting. I guess making the MWE simplified it enough I figured out what was wrong.
My defined command had an invisible space in it - that was all that was showing up, I think. See the two spots where I inserted a % at the end of the line:
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
newcommand{scalebar}[5][white]{%
begin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.05,0.4cm) node[anchor=south west] { SI{#4}{#5} };
end{scope}
end{tikzpicture}%
}
add a comment |
Ok, I figured this a little after posting. I guess making the MWE simplified it enough I figured out what was wrong.
My defined command had an invisible space in it - that was all that was showing up, I think. See the two spots where I inserted a % at the end of the line:
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
newcommand{scalebar}[5][white]{%
begin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.05,0.4cm) node[anchor=south west] { SI{#4}{#5} };
end{scope}
end{tikzpicture}%
}
Ok, I figured this a little after posting. I guess making the MWE simplified it enough I figured out what was wrong.
My defined command had an invisible space in it - that was all that was showing up, I think. See the two spots where I inserted a % at the end of the line:
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
newcommand{scalebar}[5][white]{%
begin{tikzpicture}
draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
begin{scope}[x={(image.south east)},y={(image.north west)}]
fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
draw [#1] (0.05,0.4cm) node[anchor=south west] { SI{#4}{#5} };
end{scope}
end{tikzpicture}%
}
answered Feb 28 at 0:18
argentum2fargentum2f
1216
1216
add a comment |
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%2f477054%2fhow-do-i-remove-extra-padding-from-drawing-on-a-figure-with-tikz%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
1
What happens if you set
outer sep=0
?– marmot
Feb 28 at 0:12
Sorry, I clarified I meant the padding between subfigures (not the padding around the drawing within the figure)
– argentum2f
Feb 28 at 0:22
You also add space almost every time you end a line with
}
instead of}%
.– John Kormylo
Feb 28 at 5:07