spacing when using subfloat
Consider this example:
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
end{document}
In the output:
the spacing between the subcaptions blurs. I could manually fix by inserting hspace{0.2cm}
after the first subfloat.
Is there a better, automatic way of inserting a spacing between the subfloats?
spacing subfloats subfig
add a comment |
Consider this example:
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
end{document}
In the output:
the spacing between the subcaptions blurs. I could manually fix by inserting hspace{0.2cm}
after the first subfloat.
Is there a better, automatic way of inserting a spacing between the subfloats?
spacing subfloats subfig
1
Likehfill
instead of a specific length?
– Torbjørn T.
Jan 19 at 17:26
add a comment |
Consider this example:
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
end{document}
In the output:
the spacing between the subcaptions blurs. I could manually fix by inserting hspace{0.2cm}
after the first subfloat.
Is there a better, automatic way of inserting a spacing between the subfloats?
spacing subfloats subfig
Consider this example:
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
end{document}
In the output:
the spacing between the subcaptions blurs. I could manually fix by inserting hspace{0.2cm}
after the first subfloat.
Is there a better, automatic way of inserting a spacing between the subfloats?
spacing subfloats subfig
spacing subfloats subfig
asked Jan 19 at 17:19
ViestursViesturs
1,65031123
1,65031123
1
Likehfill
instead of a specific length?
– Torbjørn T.
Jan 19 at 17:26
add a comment |
1
Likehfill
instead of a specific length?
– Torbjørn T.
Jan 19 at 17:26
1
1
Like
hfill
instead of a specific length?– Torbjørn T.
Jan 19 at 17:26
Like
hfill
instead of a specific length?– Torbjørn T.
Jan 19 at 17:26
add a comment |
3 Answers
3
active
oldest
votes
There are two problems with your code.
Each image has a normal interword space on either side, generated by the endlines inside subfloat
and you should watch out for them.
Second, the working of subfloat
ends with ignorespaces
, so the endline after the closing brace of the first subfloat
doesn't generate space between the two parts.
You can insert instead hfill
so the two images will be pushed to the margins leaving 0.1textwidth
space in the middle. Or you can use hfil
and you will have three equal spaces, left, center and right.
With the help of showframe
we can see the boundaries of the text block. Choose a style and stick to it.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfil
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfill
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Don't forget the %
bits in the places I added them.
There is a third possibility: setting some margin for the subcaptions.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
captionsetup[subfloat]{margin=1em}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Shouldtwidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?
– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use alsocaption{}
andlabel{}
do they also need a trailing%
?
– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
@Viesturs%
should be added when the endline would give an unwanted space.
– egreg
yesterday
|
show 1 more comment
A solution with floatrow
:
documentclass{report}
usepackage[showframe]{geometry}
usepackage{subfig}
usepackage{floatrow}
usepackage{graphicx}
usepackage{lipsum}
DeclareFloatSeparators{Fil}{hspace*{0.1textwidth}}
begin{document}
begin{figure}[htp]
floatsetup[figure]{floatrowsep=Fil, objectset=centering, margins=centering}%
centering
begin{subfloatrow}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-a}}{caption{lipsum[1]}}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-b}}{caption{lipsum[2]}}
end{subfloatrow}
end{figure}
end{document}
add a comment |
With the method you used, the caption text will be misaligned with the figure. For your particular case, it is not noticeable, but for other cases, it could be.
You can use hfill
which will 'horizontally' fill a space between the two figures in such a way that each one will be on one end of the text width
A more advanced way can be useful if you have multiple figures. Use hspace{stretch{<factor>}}
to specify a share for each given spacing. For instance, if you use hspace{stretch{2}}
and hspace{stretch{5}}
, then the second spacing will be 5/2 = 2.5 times larger than the first one like this
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{float}
usepackage{lipsum}
usepackage[showframe=true]{geometry}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
%
hfill
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
begin{figure}
centering
subfloat[{lipsum[1]}]{
includegraphics[width=0.25textwidth]{example-image-a}
}
%
hspace{stretch{2}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-b}
}
%
hspace{stretch{5}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-c}
}
end{figure}
end{document}
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%2f470904%2fspacing-when-using-subfloat%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two problems with your code.
Each image has a normal interword space on either side, generated by the endlines inside subfloat
and you should watch out for them.
Second, the working of subfloat
ends with ignorespaces
, so the endline after the closing brace of the first subfloat
doesn't generate space between the two parts.
You can insert instead hfill
so the two images will be pushed to the margins leaving 0.1textwidth
space in the middle. Or you can use hfil
and you will have three equal spaces, left, center and right.
With the help of showframe
we can see the boundaries of the text block. Choose a style and stick to it.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfil
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfill
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Don't forget the %
bits in the places I added them.
There is a third possibility: setting some margin for the subcaptions.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
captionsetup[subfloat]{margin=1em}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Shouldtwidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?
– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use alsocaption{}
andlabel{}
do they also need a trailing%
?
– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
@Viesturs%
should be added when the endline would give an unwanted space.
– egreg
yesterday
|
show 1 more comment
There are two problems with your code.
Each image has a normal interword space on either side, generated by the endlines inside subfloat
and you should watch out for them.
Second, the working of subfloat
ends with ignorespaces
, so the endline after the closing brace of the first subfloat
doesn't generate space between the two parts.
You can insert instead hfill
so the two images will be pushed to the margins leaving 0.1textwidth
space in the middle. Or you can use hfil
and you will have three equal spaces, left, center and right.
With the help of showframe
we can see the boundaries of the text block. Choose a style and stick to it.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfil
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfill
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Don't forget the %
bits in the places I added them.
There is a third possibility: setting some margin for the subcaptions.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
captionsetup[subfloat]{margin=1em}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Shouldtwidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?
– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use alsocaption{}
andlabel{}
do they also need a trailing%
?
– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
@Viesturs%
should be added when the endline would give an unwanted space.
– egreg
yesterday
|
show 1 more comment
There are two problems with your code.
Each image has a normal interword space on either side, generated by the endlines inside subfloat
and you should watch out for them.
Second, the working of subfloat
ends with ignorespaces
, so the endline after the closing brace of the first subfloat
doesn't generate space between the two parts.
You can insert instead hfill
so the two images will be pushed to the margins leaving 0.1textwidth
space in the middle. Or you can use hfil
and you will have three equal spaces, left, center and right.
With the help of showframe
we can see the boundaries of the text block. Choose a style and stick to it.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfil
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfill
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Don't forget the %
bits in the places I added them.
There is a third possibility: setting some margin for the subcaptions.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
captionsetup[subfloat]{margin=1em}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
There are two problems with your code.
Each image has a normal interword space on either side, generated by the endlines inside subfloat
and you should watch out for them.
Second, the working of subfloat
ends with ignorespaces
, so the endline after the closing brace of the first subfloat
doesn't generate space between the two parts.
You can insert instead hfill
so the two images will be pushed to the margins leaving 0.1textwidth
space in the middle. Or you can use hfil
and you will have three equal spaces, left, center and right.
With the help of showframe
we can see the boundaries of the text block. Choose a style and stick to it.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfil
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}hfill
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
Don't forget the %
bits in the places I added them.
There is a third possibility: setting some margin for the subcaptions.
documentclass{report}
usepackage{subfig}
usepackage{graphicx,showframe}
usepackage{lipsum}
captionsetup[subfloat]{margin=1em}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-a}%
}
subfloat[{lipsum[2][1-3]}]{%
includegraphics[width=twidthtextwidth]{example-image-b}%
}
end{figure}
end{document}
answered Jan 20 at 0:31
egregegreg
715k8619003187
715k8619003187
Shouldtwidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?
– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use alsocaption{}
andlabel{}
do they also need a trailing%
?
– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
@Viesturs%
should be added when the endline would give an unwanted space.
– egreg
yesterday
|
show 1 more comment
Shouldtwidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?
– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use alsocaption{}
andlabel{}
do they also need a trailing%
?
– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
@Viesturs%
should be added when the endline would give an unwanted space.
– egreg
yesterday
Should
twidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?– Viesturs
Jan 20 at 11:37
Should
twidth
be adjusted manually in order that after the extra spaces are added a newline is not started or is there some recipe?– Viesturs
Jan 20 at 11:37
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
@Viesturs To start a new row of subfloats, leave a blank line.
– egreg
Jan 20 at 12:04
in case I use also
caption{}
and label{}
do they also need a trailing %
?– Viesturs
Jan 23 at 16:56
in case I use also
caption{}
and label{}
do they also need a trailing %
?– Viesturs
Jan 23 at 16:56
@Viesturs No, why?
– egreg
Jan 23 at 17:02
@Viesturs No, why?
– egreg
Jan 23 at 17:02
1
1
@Viesturs
%
should be added when the endline would give an unwanted space.– egreg
yesterday
@Viesturs
%
should be added when the endline would give an unwanted space.– egreg
yesterday
|
show 1 more comment
A solution with floatrow
:
documentclass{report}
usepackage[showframe]{geometry}
usepackage{subfig}
usepackage{floatrow}
usepackage{graphicx}
usepackage{lipsum}
DeclareFloatSeparators{Fil}{hspace*{0.1textwidth}}
begin{document}
begin{figure}[htp]
floatsetup[figure]{floatrowsep=Fil, objectset=centering, margins=centering}%
centering
begin{subfloatrow}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-a}}{caption{lipsum[1]}}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-b}}{caption{lipsum[2]}}
end{subfloatrow}
end{figure}
end{document}
add a comment |
A solution with floatrow
:
documentclass{report}
usepackage[showframe]{geometry}
usepackage{subfig}
usepackage{floatrow}
usepackage{graphicx}
usepackage{lipsum}
DeclareFloatSeparators{Fil}{hspace*{0.1textwidth}}
begin{document}
begin{figure}[htp]
floatsetup[figure]{floatrowsep=Fil, objectset=centering, margins=centering}%
centering
begin{subfloatrow}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-a}}{caption{lipsum[1]}}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-b}}{caption{lipsum[2]}}
end{subfloatrow}
end{figure}
end{document}
add a comment |
A solution with floatrow
:
documentclass{report}
usepackage[showframe]{geometry}
usepackage{subfig}
usepackage{floatrow}
usepackage{graphicx}
usepackage{lipsum}
DeclareFloatSeparators{Fil}{hspace*{0.1textwidth}}
begin{document}
begin{figure}[htp]
floatsetup[figure]{floatrowsep=Fil, objectset=centering, margins=centering}%
centering
begin{subfloatrow}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-a}}{caption{lipsum[1]}}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-b}}{caption{lipsum[2]}}
end{subfloatrow}
end{figure}
end{document}
A solution with floatrow
:
documentclass{report}
usepackage[showframe]{geometry}
usepackage{subfig}
usepackage{floatrow}
usepackage{graphicx}
usepackage{lipsum}
DeclareFloatSeparators{Fil}{hspace*{0.1textwidth}}
begin{document}
begin{figure}[htp]
floatsetup[figure]{floatrowsep=Fil, objectset=centering, margins=centering}%
centering
begin{subfloatrow}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-a}}{caption{lipsum[1]}}
ffigbox[FBwidth]{includegraphics[width=0.45textwidth]{example-image-b}}{caption{lipsum[2]}}
end{subfloatrow}
end{figure}
end{document}
answered Jan 19 at 18:54
BernardBernard
168k771195
168k771195
add a comment |
add a comment |
With the method you used, the caption text will be misaligned with the figure. For your particular case, it is not noticeable, but for other cases, it could be.
You can use hfill
which will 'horizontally' fill a space between the two figures in such a way that each one will be on one end of the text width
A more advanced way can be useful if you have multiple figures. Use hspace{stretch{<factor>}}
to specify a share for each given spacing. For instance, if you use hspace{stretch{2}}
and hspace{stretch{5}}
, then the second spacing will be 5/2 = 2.5 times larger than the first one like this
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{float}
usepackage{lipsum}
usepackage[showframe=true]{geometry}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
%
hfill
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
begin{figure}
centering
subfloat[{lipsum[1]}]{
includegraphics[width=0.25textwidth]{example-image-a}
}
%
hspace{stretch{2}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-b}
}
%
hspace{stretch{5}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-c}
}
end{figure}
end{document}
add a comment |
With the method you used, the caption text will be misaligned with the figure. For your particular case, it is not noticeable, but for other cases, it could be.
You can use hfill
which will 'horizontally' fill a space between the two figures in such a way that each one will be on one end of the text width
A more advanced way can be useful if you have multiple figures. Use hspace{stretch{<factor>}}
to specify a share for each given spacing. For instance, if you use hspace{stretch{2}}
and hspace{stretch{5}}
, then the second spacing will be 5/2 = 2.5 times larger than the first one like this
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{float}
usepackage{lipsum}
usepackage[showframe=true]{geometry}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
%
hfill
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
begin{figure}
centering
subfloat[{lipsum[1]}]{
includegraphics[width=0.25textwidth]{example-image-a}
}
%
hspace{stretch{2}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-b}
}
%
hspace{stretch{5}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-c}
}
end{figure}
end{document}
add a comment |
With the method you used, the caption text will be misaligned with the figure. For your particular case, it is not noticeable, but for other cases, it could be.
You can use hfill
which will 'horizontally' fill a space between the two figures in such a way that each one will be on one end of the text width
A more advanced way can be useful if you have multiple figures. Use hspace{stretch{<factor>}}
to specify a share for each given spacing. For instance, if you use hspace{stretch{2}}
and hspace{stretch{5}}
, then the second spacing will be 5/2 = 2.5 times larger than the first one like this
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{float}
usepackage{lipsum}
usepackage[showframe=true]{geometry}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
%
hfill
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
begin{figure}
centering
subfloat[{lipsum[1]}]{
includegraphics[width=0.25textwidth]{example-image-a}
}
%
hspace{stretch{2}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-b}
}
%
hspace{stretch{5}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-c}
}
end{figure}
end{document}
With the method you used, the caption text will be misaligned with the figure. For your particular case, it is not noticeable, but for other cases, it could be.
You can use hfill
which will 'horizontally' fill a space between the two figures in such a way that each one will be on one end of the text width
A more advanced way can be useful if you have multiple figures. Use hspace{stretch{<factor>}}
to specify a share for each given spacing. For instance, if you use hspace{stretch{2}}
and hspace{stretch{5}}
, then the second spacing will be 5/2 = 2.5 times larger than the first one like this
documentclass{report}
usepackage{subfig}
usepackage{graphicx}
usepackage{float}
usepackage{lipsum}
usepackage[showframe=true]{geometry}
begin{document}
begin{figure}[htp]
centering
deftwidth{0.45}
subfloat[{lipsum[1]}]{
includegraphics[width=twidthtextwidth]{example-image-a}
}
%
hfill
subfloat[{lipsum[2]}]{
includegraphics[width=twidthtextwidth]{example-image-b}
}
end{figure}
begin{figure}
centering
subfloat[{lipsum[1]}]{
includegraphics[width=0.25textwidth]{example-image-a}
}
%
hspace{stretch{2}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-b}
}
%
hspace{stretch{5}}
subfloat[{lipsum[2]}]{
includegraphics[width=0.25textwidth]{example-image-c}
}
end{figure}
end{document}
edited Jan 19 at 20:09
answered Jan 19 at 20:03
Al-Motasem AldaoudeyehAl-Motasem Aldaoudeyeh
1,515312
1,515312
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%2f470904%2fspacing-when-using-subfloat%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
Like
hfill
instead of a specific length?– Torbjørn T.
Jan 19 at 17:26