How to make a picture taking the maximum space?












6














To expand a picture imported with includegraphics that is wider than heigh to the width of the text block, you just do this:



includegraphics[width=textwidth]{ ... }


When they are heigher than wide, you could do pretty much the same with the text height:



includegraphics[height=textheight]{ ... }


However, because pictures are often included in floats, there is a caption. This caption has a certain height and includegraphics[height=textheight]{ ... } make the figure overflow in the margin.



This leads to the following:




  1. Is there a way to tell to includegraphics that the height of the picture must be the difference between textheight and the height of the caption (with the needed space around of course)?

  2. How to generalise this kind of behaviour to the case where there are several floats or subfloats in the same “row” or “column” by saying to includegraphics something like “take the maximum allowed space”?


I think it could be more general and maybe someone else could expand or precise this.





daleif suggested to use the adjustbox package. It is very interesting and gives access to the maximum dimensions of pictures.



I tried two interesting things:





  1. To use adjincludegraphics in place of includegraphics inside a figure environment:



    begin{figure}
    adjincludegraphics[max height=textheight]{ ... }
    caption{Some text}


    I also tried max totalheight, but I don’t see a difference (the manual doesn’t say anything about it.) This doesn’t work: the picture is scaled but the caption is still outside the margins.




  2. To use the adjustbox environment which can emulate floats:



    begin{adjustbox}{float=figure,caption={Some text}, max height=textheight}
    includegraphics{ ... }
    end{adjustbox}


    This does not work unless I remove float=figure (and then there is no caption.) The figure (alone) option doesn’t work either. With float=figure, there is absolutely nothing appearing in the document but a blank page.




I think the second solution is better, but I can’t get it working properly.










share|improve this question




















  • 1




    Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
    – daleif
    Feb 6 '15 at 16:55










  • Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
    – daleif
    Feb 6 '15 at 16:55
















6














To expand a picture imported with includegraphics that is wider than heigh to the width of the text block, you just do this:



includegraphics[width=textwidth]{ ... }


When they are heigher than wide, you could do pretty much the same with the text height:



includegraphics[height=textheight]{ ... }


However, because pictures are often included in floats, there is a caption. This caption has a certain height and includegraphics[height=textheight]{ ... } make the figure overflow in the margin.



This leads to the following:




  1. Is there a way to tell to includegraphics that the height of the picture must be the difference between textheight and the height of the caption (with the needed space around of course)?

  2. How to generalise this kind of behaviour to the case where there are several floats or subfloats in the same “row” or “column” by saying to includegraphics something like “take the maximum allowed space”?


I think it could be more general and maybe someone else could expand or precise this.





daleif suggested to use the adjustbox package. It is very interesting and gives access to the maximum dimensions of pictures.



I tried two interesting things:





  1. To use adjincludegraphics in place of includegraphics inside a figure environment:



    begin{figure}
    adjincludegraphics[max height=textheight]{ ... }
    caption{Some text}


    I also tried max totalheight, but I don’t see a difference (the manual doesn’t say anything about it.) This doesn’t work: the picture is scaled but the caption is still outside the margins.




  2. To use the adjustbox environment which can emulate floats:



    begin{adjustbox}{float=figure,caption={Some text}, max height=textheight}
    includegraphics{ ... }
    end{adjustbox}


    This does not work unless I remove float=figure (and then there is no caption.) The figure (alone) option doesn’t work either. With float=figure, there is absolutely nothing appearing in the document but a blank page.




I think the second solution is better, but I can’t get it working properly.










share|improve this question




















  • 1




    Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
    – daleif
    Feb 6 '15 at 16:55










  • Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
    – daleif
    Feb 6 '15 at 16:55














6












6








6


1





To expand a picture imported with includegraphics that is wider than heigh to the width of the text block, you just do this:



includegraphics[width=textwidth]{ ... }


When they are heigher than wide, you could do pretty much the same with the text height:



includegraphics[height=textheight]{ ... }


However, because pictures are often included in floats, there is a caption. This caption has a certain height and includegraphics[height=textheight]{ ... } make the figure overflow in the margin.



This leads to the following:




  1. Is there a way to tell to includegraphics that the height of the picture must be the difference between textheight and the height of the caption (with the needed space around of course)?

  2. How to generalise this kind of behaviour to the case where there are several floats or subfloats in the same “row” or “column” by saying to includegraphics something like “take the maximum allowed space”?


I think it could be more general and maybe someone else could expand or precise this.





daleif suggested to use the adjustbox package. It is very interesting and gives access to the maximum dimensions of pictures.



I tried two interesting things:





  1. To use adjincludegraphics in place of includegraphics inside a figure environment:



    begin{figure}
    adjincludegraphics[max height=textheight]{ ... }
    caption{Some text}


    I also tried max totalheight, but I don’t see a difference (the manual doesn’t say anything about it.) This doesn’t work: the picture is scaled but the caption is still outside the margins.




  2. To use the adjustbox environment which can emulate floats:



    begin{adjustbox}{float=figure,caption={Some text}, max height=textheight}
    includegraphics{ ... }
    end{adjustbox}


    This does not work unless I remove float=figure (and then there is no caption.) The figure (alone) option doesn’t work either. With float=figure, there is absolutely nothing appearing in the document but a blank page.




I think the second solution is better, but I can’t get it working properly.










share|improve this question















To expand a picture imported with includegraphics that is wider than heigh to the width of the text block, you just do this:



includegraphics[width=textwidth]{ ... }


When they are heigher than wide, you could do pretty much the same with the text height:



includegraphics[height=textheight]{ ... }


However, because pictures are often included in floats, there is a caption. This caption has a certain height and includegraphics[height=textheight]{ ... } make the figure overflow in the margin.



This leads to the following:




  1. Is there a way to tell to includegraphics that the height of the picture must be the difference between textheight and the height of the caption (with the needed space around of course)?

  2. How to generalise this kind of behaviour to the case where there are several floats or subfloats in the same “row” or “column” by saying to includegraphics something like “take the maximum allowed space”?


I think it could be more general and maybe someone else could expand or precise this.





daleif suggested to use the adjustbox package. It is very interesting and gives access to the maximum dimensions of pictures.



I tried two interesting things:





  1. To use adjincludegraphics in place of includegraphics inside a figure environment:



    begin{figure}
    adjincludegraphics[max height=textheight]{ ... }
    caption{Some text}


    I also tried max totalheight, but I don’t see a difference (the manual doesn’t say anything about it.) This doesn’t work: the picture is scaled but the caption is still outside the margins.




  2. To use the adjustbox environment which can emulate floats:



    begin{adjustbox}{float=figure,caption={Some text}, max height=textheight}
    includegraphics{ ... }
    end{adjustbox}


    This does not work unless I remove float=figure (and then there is no caption.) The figure (alone) option doesn’t work either. With float=figure, there is absolutely nothing appearing in the document but a blank page.




I think the second solution is better, but I can’t get it working properly.







graphics floats scale






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 15:06









Martin Scharrer

199k45632815




199k45632815










asked Feb 5 '15 at 15:56









Zoxume

800314




800314








  • 1




    Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
    – daleif
    Feb 6 '15 at 16:55










  • Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
    – daleif
    Feb 6 '15 at 16:55














  • 1




    Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
    – daleif
    Feb 6 '15 at 16:55










  • Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
    – daleif
    Feb 6 '15 at 16:55








1




1




Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
– daleif
Feb 6 '15 at 16:55




Of course you cannot use max-height=textheight, then there is no room left for the caption. Perhaps something like max height=0.9textheight,max width=textwidth,keepaspectratio is better for your needs
– daleif
Feb 6 '15 at 16:55












Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
– daleif
Feb 6 '15 at 16:55




Also if you use the export (AFAIR) option for adjustbox those options also apply directly to includegraphics
– daleif
Feb 6 '15 at 16:55










2 Answers
2






active

oldest

votes


















3














See the adjustbox package, it can add features to includegraphics, including an max width/max height option that might be useful in your case.






share|improve this answer





















  • Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
    – Zoxume
    Feb 6 '15 at 16:47



















0














The order of the used keys is important. As you create a float the resizing must be done beforehand, i.e. max height first, then define the caption and finally tell adjustbox that you want a figure (figure key or float=figure).
If you use the caption key after figure it comes to late. max height after figure will create a figure environment inside a resizebox which does not work.



You should use textheight-baselineskip as maximum height as you still need space for the caption (increase to 2baselineskip if you have a two line caption and so on).



Note that there is also adjustimage which reduces the amount of code.



documentclass{article}

usepackage{adjustbox}
usepackage{mwe}% for example text and image only

begin{document}
blindtext

begin{adjustbox}{max height=textheight-baselineskip,center,caption={Some text},float=figure}
includegraphics{example-image-a3}
end{adjustbox}
% or just
%adjustimage{max height=textheight-baselineskip,center,caption={Some %text},float=figure}{example-image-a3}

blindtext

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%2f226707%2fhow-to-make-a-picture-taking-the-maximum-space%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    See the adjustbox package, it can add features to includegraphics, including an max width/max height option that might be useful in your case.






    share|improve this answer





















    • Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
      – Zoxume
      Feb 6 '15 at 16:47
















    3














    See the adjustbox package, it can add features to includegraphics, including an max width/max height option that might be useful in your case.






    share|improve this answer





















    • Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
      – Zoxume
      Feb 6 '15 at 16:47














    3












    3








    3






    See the adjustbox package, it can add features to includegraphics, including an max width/max height option that might be useful in your case.






    share|improve this answer












    See the adjustbox package, it can add features to includegraphics, including an max width/max height option that might be useful in your case.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 5 '15 at 15:59









    daleif

    32.2k252115




    32.2k252115












    • Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
      – Zoxume
      Feb 6 '15 at 16:47


















    • Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
      – Zoxume
      Feb 6 '15 at 16:47
















    Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
    – Zoxume
    Feb 6 '15 at 16:47




    Thank you for your answer, but I have issues with adjustbox. I edited my first post with more details.
    – Zoxume
    Feb 6 '15 at 16:47











    0














    The order of the used keys is important. As you create a float the resizing must be done beforehand, i.e. max height first, then define the caption and finally tell adjustbox that you want a figure (figure key or float=figure).
    If you use the caption key after figure it comes to late. max height after figure will create a figure environment inside a resizebox which does not work.



    You should use textheight-baselineskip as maximum height as you still need space for the caption (increase to 2baselineskip if you have a two line caption and so on).



    Note that there is also adjustimage which reduces the amount of code.



    documentclass{article}

    usepackage{adjustbox}
    usepackage{mwe}% for example text and image only

    begin{document}
    blindtext

    begin{adjustbox}{max height=textheight-baselineskip,center,caption={Some text},float=figure}
    includegraphics{example-image-a3}
    end{adjustbox}
    % or just
    %adjustimage{max height=textheight-baselineskip,center,caption={Some %text},float=figure}{example-image-a3}

    blindtext

    end{document}





    share|improve this answer


























      0














      The order of the used keys is important. As you create a float the resizing must be done beforehand, i.e. max height first, then define the caption and finally tell adjustbox that you want a figure (figure key or float=figure).
      If you use the caption key after figure it comes to late. max height after figure will create a figure environment inside a resizebox which does not work.



      You should use textheight-baselineskip as maximum height as you still need space for the caption (increase to 2baselineskip if you have a two line caption and so on).



      Note that there is also adjustimage which reduces the amount of code.



      documentclass{article}

      usepackage{adjustbox}
      usepackage{mwe}% for example text and image only

      begin{document}
      blindtext

      begin{adjustbox}{max height=textheight-baselineskip,center,caption={Some text},float=figure}
      includegraphics{example-image-a3}
      end{adjustbox}
      % or just
      %adjustimage{max height=textheight-baselineskip,center,caption={Some %text},float=figure}{example-image-a3}

      blindtext

      end{document}





      share|improve this answer
























        0












        0








        0






        The order of the used keys is important. As you create a float the resizing must be done beforehand, i.e. max height first, then define the caption and finally tell adjustbox that you want a figure (figure key or float=figure).
        If you use the caption key after figure it comes to late. max height after figure will create a figure environment inside a resizebox which does not work.



        You should use textheight-baselineskip as maximum height as you still need space for the caption (increase to 2baselineskip if you have a two line caption and so on).



        Note that there is also adjustimage which reduces the amount of code.



        documentclass{article}

        usepackage{adjustbox}
        usepackage{mwe}% for example text and image only

        begin{document}
        blindtext

        begin{adjustbox}{max height=textheight-baselineskip,center,caption={Some text},float=figure}
        includegraphics{example-image-a3}
        end{adjustbox}
        % or just
        %adjustimage{max height=textheight-baselineskip,center,caption={Some %text},float=figure}{example-image-a3}

        blindtext

        end{document}





        share|improve this answer












        The order of the used keys is important. As you create a float the resizing must be done beforehand, i.e. max height first, then define the caption and finally tell adjustbox that you want a figure (figure key or float=figure).
        If you use the caption key after figure it comes to late. max height after figure will create a figure environment inside a resizebox which does not work.



        You should use textheight-baselineskip as maximum height as you still need space for the caption (increase to 2baselineskip if you have a two line caption and so on).



        Note that there is also adjustimage which reduces the amount of code.



        documentclass{article}

        usepackage{adjustbox}
        usepackage{mwe}% for example text and image only

        begin{document}
        blindtext

        begin{adjustbox}{max height=textheight-baselineskip,center,caption={Some text},float=figure}
        includegraphics{example-image-a3}
        end{adjustbox}
        % or just
        %adjustimage{max height=textheight-baselineskip,center,caption={Some %text},float=figure}{example-image-a3}

        blindtext

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 29 '18 at 15:05









        Martin Scharrer

        199k45632815




        199k45632815






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f226707%2fhow-to-make-a-picture-taking-the-maximum-space%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

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

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