spacing when using subfloat












1















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:
enter image description here



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?










share|improve this question


















  • 1





    Like hfill instead of a specific length?

    – Torbjørn T.
    Jan 19 at 17:26
















1















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:
enter image description here



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?










share|improve this question


















  • 1





    Like hfill instead of a specific length?

    – Torbjørn T.
    Jan 19 at 17:26














1












1








1








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:
enter image description here



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?










share|improve this question














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:
enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 17:19









ViestursViesturs

1,65031123




1,65031123








  • 1





    Like hfill instead of a specific length?

    – Torbjørn T.
    Jan 19 at 17:26














  • 1





    Like hfill 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










3 Answers
3






active

oldest

votes


















1














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.



image



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}


enter image description here






share|improve this answer
























  • 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











  • 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






  • 1





    @Viesturs % should be added when the endline would give an unwanted space.

    – egreg
    yesterday



















1














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}


enter image description here






share|improve this answer































    1














    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



    enter image description here



    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



    enter image description here



    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}





    share|improve this answer

























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      1














      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.



      image



      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}


      enter image description here






      share|improve this answer
























      • 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











      • 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






      • 1





        @Viesturs % should be added when the endline would give an unwanted space.

        – egreg
        yesterday
















      1














      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.



      image



      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}


      enter image description here






      share|improve this answer
























      • 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











      • 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






      • 1





        @Viesturs % should be added when the endline would give an unwanted space.

        – egreg
        yesterday














      1












      1








      1







      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.



      image



      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}


      enter image description here






      share|improve this answer













      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.



      image



      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}


      enter image description here







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 20 at 0:31









      egregegreg

      715k8619003187




      715k8619003187













      • 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











      • 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






      • 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











      • @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











      • @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











      1














      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}


      enter image description here






      share|improve this answer




























        1














        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}


        enter image description here






        share|improve this answer


























          1












          1








          1







          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}


          enter image description here






          share|improve this answer













          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}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 19 at 18:54









          BernardBernard

          168k771195




          168k771195























              1














              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



              enter image description here



              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



              enter image description here



              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}





              share|improve this answer






























                1














                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



                enter image description here



                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



                enter image description here



                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}





                share|improve this answer




























                  1












                  1








                  1







                  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



                  enter image description here



                  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



                  enter image description here



                  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}





                  share|improve this answer















                  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



                  enter image description here



                  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



                  enter image description here



                  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}






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 19 at 20:09

























                  answered Jan 19 at 20:03









                  Al-Motasem AldaoudeyehAl-Motasem Aldaoudeyeh

                  1,515312




                  1,515312






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?