How can I hide a figure but keep its numbering?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
1












I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:



documentclassarticle

usepackagegraphicx

begindocument

Figure reffigure1 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure

enddocument


Then I would like to hide figure 1 from PDF output, but label figure1 should still work, and the second picture should still be numbered as 2. Is it possible?



I tried with the comment environment but it does not work.







share|improve this question




















  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
    – Zarko
    Aug 30 at 16:01










  • Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
    – JPG
    Aug 30 at 16:04










  • @JPG: Do you always have label inside caption?
    – Werner
    Aug 30 at 16:18










  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.
    – JPG
    Aug 30 at 16:20










  • What should happen to the caption? Should it still go to the LoF?
    – Skillmon
    Aug 30 at 21:45














up vote
4
down vote

favorite
1












I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:



documentclassarticle

usepackagegraphicx

begindocument

Figure reffigure1 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure

enddocument


Then I would like to hide figure 1 from PDF output, but label figure1 should still work, and the second picture should still be numbered as 2. Is it possible?



I tried with the comment environment but it does not work.







share|improve this question




















  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
    – Zarko
    Aug 30 at 16:01










  • Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
    – JPG
    Aug 30 at 16:04










  • @JPG: Do you always have label inside caption?
    – Werner
    Aug 30 at 16:18










  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.
    – JPG
    Aug 30 at 16:20










  • What should happen to the caption? Should it still go to the LoF?
    – Skillmon
    Aug 30 at 21:45












up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:



documentclassarticle

usepackagegraphicx

begindocument

Figure reffigure1 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure

enddocument


Then I would like to hide figure 1 from PDF output, but label figure1 should still work, and the second picture should still be numbered as 2. Is it possible?



I tried with the comment environment but it does not work.







share|improve this question












I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:



documentclassarticle

usepackagegraphicx

begindocument

Figure reffigure1 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure

enddocument


Then I would like to hide figure 1 from PDF output, but label figure1 should still work, and the second picture should still be numbered as 2. Is it possible?



I tried with the comment environment but it does not work.









share|improve this question











share|improve this question




share|improve this question










asked Aug 30 at 15:26









JPG

72739




72739











  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
    – Zarko
    Aug 30 at 16:01










  • Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
    – JPG
    Aug 30 at 16:04










  • @JPG: Do you always have label inside caption?
    – Werner
    Aug 30 at 16:18










  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.
    – JPG
    Aug 30 at 16:20










  • What should happen to the caption? Should it still go to the LoF?
    – Skillmon
    Aug 30 at 21:45
















  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
    – Zarko
    Aug 30 at 16:01










  • Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
    – JPG
    Aug 30 at 16:04










  • @JPG: Do you always have label inside caption?
    – Werner
    Aug 30 at 16:18










  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.
    – JPG
    Aug 30 at 16:20










  • What should happen to the caption? Should it still go to the LoF?
    – Skillmon
    Aug 30 at 21:45















if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01




if i correctly understood your question, than adding % before includegraphics is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01












Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04




Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04












@JPG: Do you always have label inside caption?
– Werner
Aug 30 at 16:18




@JPG: Do you always have label inside caption?
– Werner
Aug 30 at 16:18












@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20




@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20












What should happen to the caption? Should it still go to the LoF?
– Skillmon
Aug 30 at 21:45




What should happen to the caption? Should it still go to the LoF?
– Skillmon
Aug 30 at 21:45










3 Answers
3






active

oldest

votes

















up vote
4
down vote



accepted










It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure together with hidefigurestrue to hide them, or hidefiguresfalse (the default) to keep them in the document.



enter image description here



documentclassarticle

usepackagegraphicx,environ

newsaveboxfigsavebox% Box to capture figure content

newififhidefigures % Conditional to hide figures or keep them in the document

NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi


begindocument

hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)

Figure reffigure1 shows ldots

beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure

enddocument


Capturing the entire conditionalfigure contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.






share|improve this answer




















  • It works well and is easy to implement. Thanks.
    – JPG
    Aug 30 at 17:12










  • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
    – Skillmon
    Aug 30 at 20:21










  • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
    – Werner
    Aug 30 at 20:23










  • @Werner forgot about the lrbox.
    – Skillmon
    Aug 30 at 20:23

















up vote
3
down vote













Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.



enter image description here



documentclassarticle
usepackagegraphicx

begindocument

Figure reffigure1 shows ldots

beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure

Figure reffigure2 shows ldots

beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure

enddocument





share|improve this answer






















  • Why resizebox? You could as well just put the stuff in box0 and never output it.
    – Skillmon
    Aug 30 at 16:00










  • Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
    – JPG
    Aug 30 at 16:00










  • @Skillmon I've not heard of box0 before. How would you use it in this context?
    – Milo
    Aug 30 at 16:03










  • I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
    – JPG
    Aug 30 at 16:19











  • Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
    – Skillmon
    Aug 30 at 20:16

















up vote
1
down vote













If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.



documentclassarticle

usepackagegraphicx
newififhidefigures

makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start

%
conditionalfigure@finish

makeatother

begindocument
listoffigures
Figure reffigure1 shows ldots

beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure

Figure reffigure2 shows ldots

hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument


enter image description here






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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f448521%2fhow-can-i-hide-a-figure-but-keep-its-numbering%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure together with hidefigurestrue to hide them, or hidefiguresfalse (the default) to keep them in the document.



    enter image description here



    documentclassarticle

    usepackagegraphicx,environ

    newsaveboxfigsavebox% Box to capture figure content

    newififhidefigures % Conditional to hide figures or keep them in the document

    NewEnvironconditionalfigure[1][ht]%
    ifhidefigures
    % Hide this figure
    letoldlabellabel
    renewcommandlabel[1]gdeflabelname##1% Store label name
    renewcommandcaption[1]##1% Make caption just print its argument
    beginlrboxfigsavebox
    BODY % Capture enture figure body
    endlrbox
    refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
    else
    % Traditional figure environment
    beginfigure[#1]
    BODY
    endfigure
    fi


    begindocument

    hidefigurestrue % Remove conditional figures from document
    %hidefiguresfalse % Keep conditional figures in document (default)

    Figure reffigure1 shows ldots

    beginconditionalfigure[ht]
    centering
    includegraphics[width=5cm]example-image-a
    captionlabelfigure1
    endconditionalfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    captionlabelfigure2
    endfigure

    enddocument


    Capturing the entire conditionalfigure contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.






    share|improve this answer




















    • It works well and is easy to implement. Thanks.
      – JPG
      Aug 30 at 17:12










    • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
      – Skillmon
      Aug 30 at 20:21










    • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
      – Werner
      Aug 30 at 20:23










    • @Werner forgot about the lrbox.
      – Skillmon
      Aug 30 at 20:23














    up vote
    4
    down vote



    accepted










    It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure together with hidefigurestrue to hide them, or hidefiguresfalse (the default) to keep them in the document.



    enter image description here



    documentclassarticle

    usepackagegraphicx,environ

    newsaveboxfigsavebox% Box to capture figure content

    newififhidefigures % Conditional to hide figures or keep them in the document

    NewEnvironconditionalfigure[1][ht]%
    ifhidefigures
    % Hide this figure
    letoldlabellabel
    renewcommandlabel[1]gdeflabelname##1% Store label name
    renewcommandcaption[1]##1% Make caption just print its argument
    beginlrboxfigsavebox
    BODY % Capture enture figure body
    endlrbox
    refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
    else
    % Traditional figure environment
    beginfigure[#1]
    BODY
    endfigure
    fi


    begindocument

    hidefigurestrue % Remove conditional figures from document
    %hidefiguresfalse % Keep conditional figures in document (default)

    Figure reffigure1 shows ldots

    beginconditionalfigure[ht]
    centering
    includegraphics[width=5cm]example-image-a
    captionlabelfigure1
    endconditionalfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    captionlabelfigure2
    endfigure

    enddocument


    Capturing the entire conditionalfigure contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.






    share|improve this answer




















    • It works well and is easy to implement. Thanks.
      – JPG
      Aug 30 at 17:12










    • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
      – Skillmon
      Aug 30 at 20:21










    • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
      – Werner
      Aug 30 at 20:23










    • @Werner forgot about the lrbox.
      – Skillmon
      Aug 30 at 20:23












    up vote
    4
    down vote



    accepted







    up vote
    4
    down vote



    accepted






    It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure together with hidefigurestrue to hide them, or hidefiguresfalse (the default) to keep them in the document.



    enter image description here



    documentclassarticle

    usepackagegraphicx,environ

    newsaveboxfigsavebox% Box to capture figure content

    newififhidefigures % Conditional to hide figures or keep them in the document

    NewEnvironconditionalfigure[1][ht]%
    ifhidefigures
    % Hide this figure
    letoldlabellabel
    renewcommandlabel[1]gdeflabelname##1% Store label name
    renewcommandcaption[1]##1% Make caption just print its argument
    beginlrboxfigsavebox
    BODY % Capture enture figure body
    endlrbox
    refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
    else
    % Traditional figure environment
    beginfigure[#1]
    BODY
    endfigure
    fi


    begindocument

    hidefigurestrue % Remove conditional figures from document
    %hidefiguresfalse % Keep conditional figures in document (default)

    Figure reffigure1 shows ldots

    beginconditionalfigure[ht]
    centering
    includegraphics[width=5cm]example-image-a
    captionlabelfigure1
    endconditionalfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    captionlabelfigure2
    endfigure

    enddocument


    Capturing the entire conditionalfigure contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.






    share|improve this answer












    It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure together with hidefigurestrue to hide them, or hidefiguresfalse (the default) to keep them in the document.



    enter image description here



    documentclassarticle

    usepackagegraphicx,environ

    newsaveboxfigsavebox% Box to capture figure content

    newififhidefigures % Conditional to hide figures or keep them in the document

    NewEnvironconditionalfigure[1][ht]%
    ifhidefigures
    % Hide this figure
    letoldlabellabel
    renewcommandlabel[1]gdeflabelname##1% Store label name
    renewcommandcaption[1]##1% Make caption just print its argument
    beginlrboxfigsavebox
    BODY % Capture enture figure body
    endlrbox
    refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
    else
    % Traditional figure environment
    beginfigure[#1]
    BODY
    endfigure
    fi


    begindocument

    hidefigurestrue % Remove conditional figures from document
    %hidefiguresfalse % Keep conditional figures in document (default)

    Figure reffigure1 shows ldots

    beginconditionalfigure[ht]
    centering
    includegraphics[width=5cm]example-image-a
    captionlabelfigure1
    endconditionalfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    captionlabelfigure2
    endfigure

    enddocument


    Capturing the entire conditionalfigure contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 30 at 16:50









    Werner

    420k579131577




    420k579131577











    • It works well and is easy to implement. Thanks.
      – JPG
      Aug 30 at 17:12










    • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
      – Skillmon
      Aug 30 at 20:21










    • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
      – Werner
      Aug 30 at 20:23










    • @Werner forgot about the lrbox.
      – Skillmon
      Aug 30 at 20:23
















    • It works well and is easy to implement. Thanks.
      – JPG
      Aug 30 at 17:12










    • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
      – Skillmon
      Aug 30 at 20:21










    • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
      – Werner
      Aug 30 at 20:23










    • @Werner forgot about the lrbox.
      – Skillmon
      Aug 30 at 20:23















    It works well and is easy to implement. Thanks.
    – JPG
    Aug 30 at 17:12




    It works well and is easy to implement. Thanks.
    – JPG
    Aug 30 at 17:12












    Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
    – Skillmon
    Aug 30 at 20:21




    Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?
    – Skillmon
    Aug 30 at 20:21












    @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
    – Werner
    Aug 30 at 20:23




    @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabellabelname. gdef makes it available for use outside of the lrbox group.
    – Werner
    Aug 30 at 20:23












    @Werner forgot about the lrbox.
    – Skillmon
    Aug 30 at 20:23




    @Werner forgot about the lrbox.
    – Skillmon
    Aug 30 at 20:23










    up vote
    3
    down vote













    Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.



    enter image description here



    documentclassarticle
    usepackagegraphicx

    begindocument

    Figure reffigure1 shows ldots

    beginfigure[ht]
    centering
    resizebox!0cmbeginminipagetextwidth
    includegraphics[width=5cm]example-image-a
    caption
    labelfigure1
    endminipage
    endfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    caption
    labelfigure2
    endfigure

    enddocument





    share|improve this answer






















    • Why resizebox? You could as well just put the stuff in box0 and never output it.
      – Skillmon
      Aug 30 at 16:00










    • Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
      – JPG
      Aug 30 at 16:00










    • @Skillmon I've not heard of box0 before. How would you use it in this context?
      – Milo
      Aug 30 at 16:03










    • I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
      – JPG
      Aug 30 at 16:19











    • Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
      – Skillmon
      Aug 30 at 20:16














    up vote
    3
    down vote













    Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.



    enter image description here



    documentclassarticle
    usepackagegraphicx

    begindocument

    Figure reffigure1 shows ldots

    beginfigure[ht]
    centering
    resizebox!0cmbeginminipagetextwidth
    includegraphics[width=5cm]example-image-a
    caption
    labelfigure1
    endminipage
    endfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    caption
    labelfigure2
    endfigure

    enddocument





    share|improve this answer






















    • Why resizebox? You could as well just put the stuff in box0 and never output it.
      – Skillmon
      Aug 30 at 16:00










    • Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
      – JPG
      Aug 30 at 16:00










    • @Skillmon I've not heard of box0 before. How would you use it in this context?
      – Milo
      Aug 30 at 16:03










    • I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
      – JPG
      Aug 30 at 16:19











    • Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
      – Skillmon
      Aug 30 at 20:16












    up vote
    3
    down vote










    up vote
    3
    down vote









    Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.



    enter image description here



    documentclassarticle
    usepackagegraphicx

    begindocument

    Figure reffigure1 shows ldots

    beginfigure[ht]
    centering
    resizebox!0cmbeginminipagetextwidth
    includegraphics[width=5cm]example-image-a
    caption
    labelfigure1
    endminipage
    endfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    caption
    labelfigure2
    endfigure

    enddocument





    share|improve this answer














    Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.



    enter image description here



    documentclassarticle
    usepackagegraphicx

    begindocument

    Figure reffigure1 shows ldots

    beginfigure[ht]
    centering
    resizebox!0cmbeginminipagetextwidth
    includegraphics[width=5cm]example-image-a
    caption
    labelfigure1
    endminipage
    endfigure

    Figure reffigure2 shows ldots

    beginfigure[ht]
    centering
    includegraphics[width=5cm]example-image-b
    caption
    labelfigure2
    endfigure

    enddocument






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 30 at 16:04

























    answered Aug 30 at 15:53









    Milo

    5,51321345




    5,51321345











    • Why resizebox? You could as well just put the stuff in box0 and never output it.
      – Skillmon
      Aug 30 at 16:00










    • Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
      – JPG
      Aug 30 at 16:00










    • @Skillmon I've not heard of box0 before. How would you use it in this context?
      – Milo
      Aug 30 at 16:03










    • I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
      – JPG
      Aug 30 at 16:19











    • Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
      – Skillmon
      Aug 30 at 20:16
















    • Why resizebox? You could as well just put the stuff in box0 and never output it.
      – Skillmon
      Aug 30 at 16:00










    • Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
      – JPG
      Aug 30 at 16:00










    • @Skillmon I've not heard of box0 before. How would you use it in this context?
      – Milo
      Aug 30 at 16:03










    • I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
      – JPG
      Aug 30 at 16:19











    • Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
      – Skillmon
      Aug 30 at 20:16















    Why resizebox? You could as well just put the stuff in box0 and never output it.
    – Skillmon
    Aug 30 at 16:00




    Why resizebox? You could as well just put the stuff in box0 and never output it.
    – Skillmon
    Aug 30 at 16:00












    Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
    – JPG
    Aug 30 at 16:00




    Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
    – JPG
    Aug 30 at 16:00












    @Skillmon I've not heard of box0 before. How would you use it in this context?
    – Milo
    Aug 30 at 16:03




    @Skillmon I've not heard of box0 before. How would you use it in this context?
    – Milo
    Aug 30 at 16:03












    I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
    – JPG
    Aug 30 at 16:19





    I managed to obtain your output by changing resizebox!0cm to resizebox!0.000001cm; strange that it doesn't work with 0cm...
    – JPG
    Aug 30 at 16:19













    Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
    – Skillmon
    Aug 30 at 20:16




    Something like setbox0hbox.... The 0 box register is often used for temporary stuff (e.g. by smash and the like). Stuff which is typed in a setbox is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox in case of a hbox, or unvbox for vbox; there are other methods of outputting them, the simplest being box, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox or newsavebox, the latter being the LaTeX macro, the former TeX).
    – Skillmon
    Aug 30 at 20:16










    up vote
    1
    down vote













    If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.



    documentclassarticle

    usepackagegraphicx
    newififhidefigures

    makeatletter
    newenvironmentconditionalfigure[1]
    %
    ifhidefigures
    letzzwrite
    protecteddefwriteimmediatezz%
    defconditionalfigure@start
    %
    def@captypefiguresetbox0vboxbgroupcolor@setgroup
    %
    defconditionalfigure@finish
    %
    color@endgroupegroup
    %
    else
    ifrelaxdetokenize#1relax
    defconditionalfigure@start
    beginfigure%
    else
    defconditionalfigure@start
    beginfigure[#1]%
    fi
    defconditionalfigure@finish
    endfigure%
    fi
    conditionalfigure@start

    %
    conditionalfigure@finish

    makeatother

    begindocument
    listoffigures
    Figure reffigure1 shows ldots

    beginconditionalfigure
    centering
    includegraphics[width=5cm]example-image-duck
    captionFigure 1labelfigure1
    endconditionalfigure

    Figure reffigure2 shows ldots

    hidefigurestrue
    beginconditionalfigure
    centering
    includegraphics[width=5cm]example-image-b
    captionFigure 2labelfigure2
    endconditionalfigure
    enddocument


    enter image description here






    share|improve this answer
























      up vote
      1
      down vote













      If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.



      documentclassarticle

      usepackagegraphicx
      newififhidefigures

      makeatletter
      newenvironmentconditionalfigure[1]
      %
      ifhidefigures
      letzzwrite
      protecteddefwriteimmediatezz%
      defconditionalfigure@start
      %
      def@captypefiguresetbox0vboxbgroupcolor@setgroup
      %
      defconditionalfigure@finish
      %
      color@endgroupegroup
      %
      else
      ifrelaxdetokenize#1relax
      defconditionalfigure@start
      beginfigure%
      else
      defconditionalfigure@start
      beginfigure[#1]%
      fi
      defconditionalfigure@finish
      endfigure%
      fi
      conditionalfigure@start

      %
      conditionalfigure@finish

      makeatother

      begindocument
      listoffigures
      Figure reffigure1 shows ldots

      beginconditionalfigure
      centering
      includegraphics[width=5cm]example-image-duck
      captionFigure 1labelfigure1
      endconditionalfigure

      Figure reffigure2 shows ldots

      hidefigurestrue
      beginconditionalfigure
      centering
      includegraphics[width=5cm]example-image-b
      captionFigure 2labelfigure2
      endconditionalfigure
      enddocument


      enter image description here






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.



        documentclassarticle

        usepackagegraphicx
        newififhidefigures

        makeatletter
        newenvironmentconditionalfigure[1]
        %
        ifhidefigures
        letzzwrite
        protecteddefwriteimmediatezz%
        defconditionalfigure@start
        %
        def@captypefiguresetbox0vboxbgroupcolor@setgroup
        %
        defconditionalfigure@finish
        %
        color@endgroupegroup
        %
        else
        ifrelaxdetokenize#1relax
        defconditionalfigure@start
        beginfigure%
        else
        defconditionalfigure@start
        beginfigure[#1]%
        fi
        defconditionalfigure@finish
        endfigure%
        fi
        conditionalfigure@start

        %
        conditionalfigure@finish

        makeatother

        begindocument
        listoffigures
        Figure reffigure1 shows ldots

        beginconditionalfigure
        centering
        includegraphics[width=5cm]example-image-duck
        captionFigure 1labelfigure1
        endconditionalfigure

        Figure reffigure2 shows ldots

        hidefigurestrue
        beginconditionalfigure
        centering
        includegraphics[width=5cm]example-image-b
        captionFigure 2labelfigure2
        endconditionalfigure
        enddocument


        enter image description here






        share|improve this answer












        If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.



        documentclassarticle

        usepackagegraphicx
        newififhidefigures

        makeatletter
        newenvironmentconditionalfigure[1]
        %
        ifhidefigures
        letzzwrite
        protecteddefwriteimmediatezz%
        defconditionalfigure@start
        %
        def@captypefiguresetbox0vboxbgroupcolor@setgroup
        %
        defconditionalfigure@finish
        %
        color@endgroupegroup
        %
        else
        ifrelaxdetokenize#1relax
        defconditionalfigure@start
        beginfigure%
        else
        defconditionalfigure@start
        beginfigure[#1]%
        fi
        defconditionalfigure@finish
        endfigure%
        fi
        conditionalfigure@start

        %
        conditionalfigure@finish

        makeatother

        begindocument
        listoffigures
        Figure reffigure1 shows ldots

        beginconditionalfigure
        centering
        includegraphics[width=5cm]example-image-duck
        captionFigure 1labelfigure1
        endconditionalfigure

        Figure reffigure2 shows ldots

        hidefigurestrue
        beginconditionalfigure
        centering
        includegraphics[width=5cm]example-image-b
        captionFigure 2labelfigure2
        endconditionalfigure
        enddocument


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 30 at 21:52









        Skillmon

        17.5k11535




        17.5k11535



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f448521%2fhow-can-i-hide-a-figure-but-keep-its-numbering%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery