How can I hide a figure but keep its numbering? Announcing the arrival of Valued Associate...

Was there ever a LEGO store in Miami International Airport?

What is the numbering system used for the DSN dishes?

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

"Working on a knee"

Could a cockatrice have parasitic embryos?

How would you suggest I follow up with coworkers about our deadline that's today?

Are there existing rules/lore for MTG planeswalkers?

Why doesn't the university give past final exams' answers?

Did war bonds have better investment alternatives during WWII?

What do you call an IPA symbol that lacks a name (e.g. ɲ)?

What is the ongoing value of the Kanban board to the developers as opposed to management

What is ls Largest Number Formed by only moving two sticks in 508?

Why does Java have support for time zone offsets with seconds precision?

Co-worker works way more than he should

Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table

Israeli soda type drink

Where to find documentation for `whois` command options?

Will I be more secure with my own router behind my ISP's router?

Retract an already submitted Recommendation Letter (written for an undergrad student)

Is there an efficient way for synchronising audio events real-time with LEDs using an MCU?

Was Objective-C really a hindrance to Apple software development?

How did Elite on the NES work?

Eigenvalues of the Laplacian of the directed De Bruijn graph

Is there a way to fake a method response using Mock or Stubs?



How can I hide a figure but keep its numbering?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern)tikz externalization and multiple axis using ref and label for legendentryForce all floats to the end of the document without using endfloatLaTeX numbering one figure incorrectly (Figure 2 instead of Figure 2.1)Lyx cross refernce to figures not working when there is a new line between caption and labelTable caption not appearing in PNAS document classRotate figure with package rotatingProblem with referencesHow to put hyperlinks in endfloat's markers?Keep Figures RIGHT AFTER textSide-by-side figures with caption, specify height but use whole textwidth












5















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:



documentclass{article}

usepackage{graphicx}

begin{document}

Figure ref{figure1} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure1.jpg}
caption{label{figure1}}
end{figure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure2.jpg}
caption{label{figure2}}
end{figure}

end{document}


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 begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

    – Zarko
    Aug 30 '18 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 '18 at 16:04











  • @JPG: Do you always have label inside caption?

    – Werner
    Aug 30 '18 at 16:18











  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.

    – JPG
    Aug 30 '18 at 16:20











  • What should happen to the caption? Should it still go to the LoF?

    – Skillmon
    Aug 30 '18 at 21:45
















5















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:



documentclass{article}

usepackage{graphicx}

begin{document}

Figure ref{figure1} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure1.jpg}
caption{label{figure1}}
end{figure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure2.jpg}
caption{label{figure2}}
end{figure}

end{document}


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 begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

    – Zarko
    Aug 30 '18 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 '18 at 16:04











  • @JPG: Do you always have label inside caption?

    – Werner
    Aug 30 '18 at 16:18











  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.

    – JPG
    Aug 30 '18 at 16:20











  • What should happen to the caption? Should it still go to the LoF?

    – Skillmon
    Aug 30 '18 at 21:45














5












5








5


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:



documentclass{article}

usepackage{graphicx}

begin{document}

Figure ref{figure1} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure1.jpg}
caption{label{figure1}}
end{figure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure2.jpg}
caption{label{figure2}}
end{figure}

end{document}


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:



documentclass{article}

usepackage{graphicx}

begin{document}

Figure ref{figure1} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure1.jpg}
caption{label{figure1}}
end{figure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{figure2.jpg}
caption{label{figure2}}
end{figure}

end{document}


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.







floats cross-referencing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 30 '18 at 15:26









JPGJPG

1,532413




1,532413













  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

    – Zarko
    Aug 30 '18 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 '18 at 16:04











  • @JPG: Do you always have label inside caption?

    – Werner
    Aug 30 '18 at 16:18











  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.

    – JPG
    Aug 30 '18 at 16:20











  • What should happen to the caption? Should it still go to the LoF?

    – Skillmon
    Aug 30 '18 at 21:45



















  • if i correctly understood your question, than adding % before includegraphics is what you looking for. for example begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

    – Zarko
    Aug 30 '18 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 '18 at 16:04











  • @JPG: Do you always have label inside caption?

    – Werner
    Aug 30 '18 at 16:18











  • @Werner: Yes, always. And sometimes I have subfigures with labels for each one.

    – JPG
    Aug 30 '18 at 16:20











  • What should happen to the caption? Should it still go to the LoF?

    – Skillmon
    Aug 30 '18 at 21:45

















if i correctly understood your question, than adding % before includegraphics is what you looking for. for example begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

– Zarko
Aug 30 '18 at 16:01





if i correctly understood your question, than adding % before includegraphics is what you looking for. for example begin{figure}[ht] centering % includegraphics[width=5cm]{figure1.jpg} caption{label{figure1}} end{figure}

– Zarko
Aug 30 '18 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 '18 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 '18 at 16:04













@JPG: Do you always have label inside caption?

– Werner
Aug 30 '18 at 16:18





@JPG: Do you always have label inside caption?

– Werner
Aug 30 '18 at 16:18













@Werner: Yes, always. And sometimes I have subfigures with labels for each one.

– JPG
Aug 30 '18 at 16:20





@Werner: Yes, always. And sometimes I have subfigures with labels for each one.

– JPG
Aug 30 '18 at 16:20













What should happen to the caption? Should it still go to the LoF?

– Skillmon
Aug 30 '18 at 21:45





What should happen to the caption? Should it still go to the LoF?

– Skillmon
Aug 30 '18 at 21:45










4 Answers
4






active

oldest

votes


















5














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



documentclass{article}

usepackage{graphicx,environ}

newsavebox{figsavebox}% Box to capture figure content

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

NewEnviron{conditionalfigure}[1][ht]{%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommand{label}[1]{gdeflabelname{##1}}% Store label name
renewcommand{caption}[1]{##1}% Make caption just print its argument
begin{lrbox}{figsavebox}
BODY % Capture enture figure body
end{lrbox}
refstepcounter{figure}oldlabel{labelname}% Step counter with reference and mark with label
else
% Traditional figure environment
begin{figure}[#1]
BODY
end{figure}
fi
}

begin{document}

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

Figure ref{figure1} shows ldots

begin{conditionalfigure}[ht]
centering
includegraphics[width=5cm]{example-image-a}
caption{label{figure1}}
end{conditionalfigure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{example-image-b}
caption{label{figure2}}
end{figure}

end{document}


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 '18 at 17:12











  • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

    – Skillmon
    Aug 30 '18 at 20:21











  • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

    – Werner
    Aug 30 '18 at 20:23











  • @Werner forgot about the lrbox.

    – Skillmon
    Aug 30 '18 at 20:23



















3














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



documentclass{article}
usepackage{graphicx}

begin{document}

Figure ref{figure1} shows ldots

begin{figure}[ht]
centering
resizebox{!}{0cm}{begin{minipage}{textwidth}
includegraphics[width=5cm]{example-image-a}
caption{}
label{figure1}
end{minipage}}
end{figure}

Figure ref{figure2} shows ldots

begin{figure}[ht]
centering
includegraphics[width=5cm]{example-image-b}
caption{}
label{figure2}
end{figure}

end{document}





share|improve this answer


























  • Why resizebox? You could as well just put the stuff in box0 and never output it.

    – Skillmon
    Aug 30 '18 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 '18 at 16:00











  • @Skillmon I've not heard of box0 before. How would you use it in this context?

    – Milo
    Aug 30 '18 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 '18 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 '18 at 20:16



















1














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.



documentclass[]{article}

usepackage[]{graphicx}
newififhidefigures

makeatletter
newenvironment{conditionalfigure}[1][]
{%
ifhidefigures
letzzwrite
protecteddefwrite{immediatezz}%
defconditionalfigure@start
{%
def@captype{figure}setbox0vboxbgroupcolor@setgroup
}%
defconditionalfigure@finish
{%
color@endgroupegroup
}%
else
ifrelaxdetokenize{#1}relax
defconditionalfigure@start
{begin{figure}}%
else
defconditionalfigure@start
{begin{figure}[#1]}%
fi
defconditionalfigure@finish
{end{figure}}%
fi
conditionalfigure@start
}
{%
conditionalfigure@finish
}
makeatother

begin{document}
listoffigures
Figure ref{figure1} shows ldots

begin{conditionalfigure}
centering
includegraphics[width=5cm]{example-image-duck}
caption{Figure 1label{figure1}}
end{conditionalfigure}

Figure ref{figure2} shows ldots

hidefigurestrue
begin{conditionalfigure}
centering
includegraphics[width=5cm]{example-image-b}
caption{Figure 2label{figure2}}
end{conditionalfigure}
end{document}


enter image description here






share|improve this answer































    0














    Simple but works: Comment out the includegraphics command.






    share|improve this answer








    New contributor




    romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      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%2f448521%2fhow-can-i-hide-a-figure-but-keep-its-numbering%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      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



      documentclass{article}

      usepackage{graphicx,environ}

      newsavebox{figsavebox}% Box to capture figure content

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

      NewEnviron{conditionalfigure}[1][ht]{%
      ifhidefigures
      % Hide this figure
      letoldlabellabel
      renewcommand{label}[1]{gdeflabelname{##1}}% Store label name
      renewcommand{caption}[1]{##1}% Make caption just print its argument
      begin{lrbox}{figsavebox}
      BODY % Capture enture figure body
      end{lrbox}
      refstepcounter{figure}oldlabel{labelname}% Step counter with reference and mark with label
      else
      % Traditional figure environment
      begin{figure}[#1]
      BODY
      end{figure}
      fi
      }

      begin{document}

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

      Figure ref{figure1} shows ldots

      begin{conditionalfigure}[ht]
      centering
      includegraphics[width=5cm]{example-image-a}
      caption{label{figure1}}
      end{conditionalfigure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{label{figure2}}
      end{figure}

      end{document}


      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 '18 at 17:12











      • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

        – Skillmon
        Aug 30 '18 at 20:21











      • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

        – Werner
        Aug 30 '18 at 20:23











      • @Werner forgot about the lrbox.

        – Skillmon
        Aug 30 '18 at 20:23
















      5














      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



      documentclass{article}

      usepackage{graphicx,environ}

      newsavebox{figsavebox}% Box to capture figure content

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

      NewEnviron{conditionalfigure}[1][ht]{%
      ifhidefigures
      % Hide this figure
      letoldlabellabel
      renewcommand{label}[1]{gdeflabelname{##1}}% Store label name
      renewcommand{caption}[1]{##1}% Make caption just print its argument
      begin{lrbox}{figsavebox}
      BODY % Capture enture figure body
      end{lrbox}
      refstepcounter{figure}oldlabel{labelname}% Step counter with reference and mark with label
      else
      % Traditional figure environment
      begin{figure}[#1]
      BODY
      end{figure}
      fi
      }

      begin{document}

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

      Figure ref{figure1} shows ldots

      begin{conditionalfigure}[ht]
      centering
      includegraphics[width=5cm]{example-image-a}
      caption{label{figure1}}
      end{conditionalfigure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{label{figure2}}
      end{figure}

      end{document}


      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 '18 at 17:12











      • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

        – Skillmon
        Aug 30 '18 at 20:21











      • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

        – Werner
        Aug 30 '18 at 20:23











      • @Werner forgot about the lrbox.

        – Skillmon
        Aug 30 '18 at 20:23














      5












      5








      5







      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



      documentclass{article}

      usepackage{graphicx,environ}

      newsavebox{figsavebox}% Box to capture figure content

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

      NewEnviron{conditionalfigure}[1][ht]{%
      ifhidefigures
      % Hide this figure
      letoldlabellabel
      renewcommand{label}[1]{gdeflabelname{##1}}% Store label name
      renewcommand{caption}[1]{##1}% Make caption just print its argument
      begin{lrbox}{figsavebox}
      BODY % Capture enture figure body
      end{lrbox}
      refstepcounter{figure}oldlabel{labelname}% Step counter with reference and mark with label
      else
      % Traditional figure environment
      begin{figure}[#1]
      BODY
      end{figure}
      fi
      }

      begin{document}

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

      Figure ref{figure1} shows ldots

      begin{conditionalfigure}[ht]
      centering
      includegraphics[width=5cm]{example-image-a}
      caption{label{figure1}}
      end{conditionalfigure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{label{figure2}}
      end{figure}

      end{document}


      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



      documentclass{article}

      usepackage{graphicx,environ}

      newsavebox{figsavebox}% Box to capture figure content

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

      NewEnviron{conditionalfigure}[1][ht]{%
      ifhidefigures
      % Hide this figure
      letoldlabellabel
      renewcommand{label}[1]{gdeflabelname{##1}}% Store label name
      renewcommand{caption}[1]{##1}% Make caption just print its argument
      begin{lrbox}{figsavebox}
      BODY % Capture enture figure body
      end{lrbox}
      refstepcounter{figure}oldlabel{labelname}% Step counter with reference and mark with label
      else
      % Traditional figure environment
      begin{figure}[#1]
      BODY
      end{figure}
      fi
      }

      begin{document}

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

      Figure ref{figure1} shows ldots

      begin{conditionalfigure}[ht]
      centering
      includegraphics[width=5cm]{example-image-a}
      caption{label{figure1}}
      end{conditionalfigure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{label{figure2}}
      end{figure}

      end{document}


      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 '18 at 16:50









      WernerWerner

      451k7310021713




      451k7310021713













      • It works well and is easy to implement. Thanks.

        – JPG
        Aug 30 '18 at 17:12











      • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

        – Skillmon
        Aug 30 '18 at 20:21











      • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

        – Werner
        Aug 30 '18 at 20:23











      • @Werner forgot about the lrbox.

        – Skillmon
        Aug 30 '18 at 20:23



















      • It works well and is easy to implement. Thanks.

        – JPG
        Aug 30 '18 at 17:12











      • Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

        – Skillmon
        Aug 30 '18 at 20:21











      • @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

        – Werner
        Aug 30 '18 at 20:23











      • @Werner forgot about the lrbox.

        – Skillmon
        Aug 30 '18 at 20:23

















      It works well and is easy to implement. Thanks.

      – JPG
      Aug 30 '18 at 17:12





      It works well and is easy to implement. Thanks.

      – JPG
      Aug 30 '18 at 17:12













      Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

      – Skillmon
      Aug 30 '18 at 20:21





      Why gdef the labelname? Wouldn't a def be enough in case of NewEnviron?

      – Skillmon
      Aug 30 '18 at 20:21













      @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

      – Werner
      Aug 30 '18 at 20:23





      @Skillmon: Within the lrbox environment where label is executed the first time, a def would render labelname undefined when using oldlabel{labelname}. gdef makes it available for use outside of the lrbox group.

      – Werner
      Aug 30 '18 at 20:23













      @Werner forgot about the lrbox.

      – Skillmon
      Aug 30 '18 at 20:23





      @Werner forgot about the lrbox.

      – Skillmon
      Aug 30 '18 at 20:23











      3














      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



      documentclass{article}
      usepackage{graphicx}

      begin{document}

      Figure ref{figure1} shows ldots

      begin{figure}[ht]
      centering
      resizebox{!}{0cm}{begin{minipage}{textwidth}
      includegraphics[width=5cm]{example-image-a}
      caption{}
      label{figure1}
      end{minipage}}
      end{figure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{}
      label{figure2}
      end{figure}

      end{document}





      share|improve this answer


























      • Why resizebox? You could as well just put the stuff in box0 and never output it.

        – Skillmon
        Aug 30 '18 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 '18 at 16:00











      • @Skillmon I've not heard of box0 before. How would you use it in this context?

        – Milo
        Aug 30 '18 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 '18 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 '18 at 20:16
















      3














      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



      documentclass{article}
      usepackage{graphicx}

      begin{document}

      Figure ref{figure1} shows ldots

      begin{figure}[ht]
      centering
      resizebox{!}{0cm}{begin{minipage}{textwidth}
      includegraphics[width=5cm]{example-image-a}
      caption{}
      label{figure1}
      end{minipage}}
      end{figure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{}
      label{figure2}
      end{figure}

      end{document}





      share|improve this answer


























      • Why resizebox? You could as well just put the stuff in box0 and never output it.

        – Skillmon
        Aug 30 '18 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 '18 at 16:00











      • @Skillmon I've not heard of box0 before. How would you use it in this context?

        – Milo
        Aug 30 '18 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 '18 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 '18 at 20:16














      3












      3








      3







      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



      documentclass{article}
      usepackage{graphicx}

      begin{document}

      Figure ref{figure1} shows ldots

      begin{figure}[ht]
      centering
      resizebox{!}{0cm}{begin{minipage}{textwidth}
      includegraphics[width=5cm]{example-image-a}
      caption{}
      label{figure1}
      end{minipage}}
      end{figure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{}
      label{figure2}
      end{figure}

      end{document}





      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



      documentclass{article}
      usepackage{graphicx}

      begin{document}

      Figure ref{figure1} shows ldots

      begin{figure}[ht]
      centering
      resizebox{!}{0cm}{begin{minipage}{textwidth}
      includegraphics[width=5cm]{example-image-a}
      caption{}
      label{figure1}
      end{minipage}}
      end{figure}

      Figure ref{figure2} shows ldots

      begin{figure}[ht]
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{}
      label{figure2}
      end{figure}

      end{document}






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 30 '18 at 16:04

























      answered Aug 30 '18 at 15:53









      MiloMilo

      6,85721951




      6,85721951













      • Why resizebox? You could as well just put the stuff in box0 and never output it.

        – Skillmon
        Aug 30 '18 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 '18 at 16:00











      • @Skillmon I've not heard of box0 before. How would you use it in this context?

        – Milo
        Aug 30 '18 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 '18 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 '18 at 20:16



















      • Why resizebox? You could as well just put the stuff in box0 and never output it.

        – Skillmon
        Aug 30 '18 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 '18 at 16:00











      • @Skillmon I've not heard of box0 before. How would you use it in this context?

        – Milo
        Aug 30 '18 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 '18 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 '18 at 20:16

















      Why resizebox? You could as well just put the stuff in box0 and never output it.

      – Skillmon
      Aug 30 '18 at 16:00





      Why resizebox? You could as well just put the stuff in box0 and never output it.

      – Skillmon
      Aug 30 '18 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 '18 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 '18 at 16:00













      @Skillmon I've not heard of box0 before. How would you use it in this context?

      – Milo
      Aug 30 '18 at 16:03





      @Skillmon I've not heard of box0 before. How would you use it in this context?

      – Milo
      Aug 30 '18 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 '18 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 '18 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 '18 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 '18 at 20:16











      1














      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.



      documentclass[]{article}

      usepackage[]{graphicx}
      newififhidefigures

      makeatletter
      newenvironment{conditionalfigure}[1][]
      {%
      ifhidefigures
      letzzwrite
      protecteddefwrite{immediatezz}%
      defconditionalfigure@start
      {%
      def@captype{figure}setbox0vboxbgroupcolor@setgroup
      }%
      defconditionalfigure@finish
      {%
      color@endgroupegroup
      }%
      else
      ifrelaxdetokenize{#1}relax
      defconditionalfigure@start
      {begin{figure}}%
      else
      defconditionalfigure@start
      {begin{figure}[#1]}%
      fi
      defconditionalfigure@finish
      {end{figure}}%
      fi
      conditionalfigure@start
      }
      {%
      conditionalfigure@finish
      }
      makeatother

      begin{document}
      listoffigures
      Figure ref{figure1} shows ldots

      begin{conditionalfigure}
      centering
      includegraphics[width=5cm]{example-image-duck}
      caption{Figure 1label{figure1}}
      end{conditionalfigure}

      Figure ref{figure2} shows ldots

      hidefigurestrue
      begin{conditionalfigure}
      centering
      includegraphics[width=5cm]{example-image-b}
      caption{Figure 2label{figure2}}
      end{conditionalfigure}
      end{document}


      enter image description here






      share|improve this answer




























        1














        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.



        documentclass[]{article}

        usepackage[]{graphicx}
        newififhidefigures

        makeatletter
        newenvironment{conditionalfigure}[1][]
        {%
        ifhidefigures
        letzzwrite
        protecteddefwrite{immediatezz}%
        defconditionalfigure@start
        {%
        def@captype{figure}setbox0vboxbgroupcolor@setgroup
        }%
        defconditionalfigure@finish
        {%
        color@endgroupegroup
        }%
        else
        ifrelaxdetokenize{#1}relax
        defconditionalfigure@start
        {begin{figure}}%
        else
        defconditionalfigure@start
        {begin{figure}[#1]}%
        fi
        defconditionalfigure@finish
        {end{figure}}%
        fi
        conditionalfigure@start
        }
        {%
        conditionalfigure@finish
        }
        makeatother

        begin{document}
        listoffigures
        Figure ref{figure1} shows ldots

        begin{conditionalfigure}
        centering
        includegraphics[width=5cm]{example-image-duck}
        caption{Figure 1label{figure1}}
        end{conditionalfigure}

        Figure ref{figure2} shows ldots

        hidefigurestrue
        begin{conditionalfigure}
        centering
        includegraphics[width=5cm]{example-image-b}
        caption{Figure 2label{figure2}}
        end{conditionalfigure}
        end{document}


        enter image description here






        share|improve this answer


























          1












          1








          1







          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.



          documentclass[]{article}

          usepackage[]{graphicx}
          newififhidefigures

          makeatletter
          newenvironment{conditionalfigure}[1][]
          {%
          ifhidefigures
          letzzwrite
          protecteddefwrite{immediatezz}%
          defconditionalfigure@start
          {%
          def@captype{figure}setbox0vboxbgroupcolor@setgroup
          }%
          defconditionalfigure@finish
          {%
          color@endgroupegroup
          }%
          else
          ifrelaxdetokenize{#1}relax
          defconditionalfigure@start
          {begin{figure}}%
          else
          defconditionalfigure@start
          {begin{figure}[#1]}%
          fi
          defconditionalfigure@finish
          {end{figure}}%
          fi
          conditionalfigure@start
          }
          {%
          conditionalfigure@finish
          }
          makeatother

          begin{document}
          listoffigures
          Figure ref{figure1} shows ldots

          begin{conditionalfigure}
          centering
          includegraphics[width=5cm]{example-image-duck}
          caption{Figure 1label{figure1}}
          end{conditionalfigure}

          Figure ref{figure2} shows ldots

          hidefigurestrue
          begin{conditionalfigure}
          centering
          includegraphics[width=5cm]{example-image-b}
          caption{Figure 2label{figure2}}
          end{conditionalfigure}
          end{document}


          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.



          documentclass[]{article}

          usepackage[]{graphicx}
          newififhidefigures

          makeatletter
          newenvironment{conditionalfigure}[1][]
          {%
          ifhidefigures
          letzzwrite
          protecteddefwrite{immediatezz}%
          defconditionalfigure@start
          {%
          def@captype{figure}setbox0vboxbgroupcolor@setgroup
          }%
          defconditionalfigure@finish
          {%
          color@endgroupegroup
          }%
          else
          ifrelaxdetokenize{#1}relax
          defconditionalfigure@start
          {begin{figure}}%
          else
          defconditionalfigure@start
          {begin{figure}[#1]}%
          fi
          defconditionalfigure@finish
          {end{figure}}%
          fi
          conditionalfigure@start
          }
          {%
          conditionalfigure@finish
          }
          makeatother

          begin{document}
          listoffigures
          Figure ref{figure1} shows ldots

          begin{conditionalfigure}
          centering
          includegraphics[width=5cm]{example-image-duck}
          caption{Figure 1label{figure1}}
          end{conditionalfigure}

          Figure ref{figure2} shows ldots

          hidefigurestrue
          begin{conditionalfigure}
          centering
          includegraphics[width=5cm]{example-image-b}
          caption{Figure 2label{figure2}}
          end{conditionalfigure}
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 30 '18 at 21:52









          SkillmonSkillmon

          24.4k12250




          24.4k12250























              0














              Simple but works: Comment out the includegraphics command.






              share|improve this answer








              New contributor




              romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                Simple but works: Comment out the includegraphics command.






                share|improve this answer








                New contributor




                romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  Simple but works: Comment out the includegraphics command.






                  share|improve this answer








                  New contributor




                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  Simple but works: Comment out the includegraphics command.







                  share|improve this answer








                  New contributor




                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 13 mins ago









                  romichromich

                  1




                  1




                  New contributor




                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  romich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      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%2f448521%2fhow-can-i-hide-a-figure-but-keep-its-numbering%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

                      El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

                      Castillo d'Acher Características Menú de navegación

                      Connecting two nodes from the same mother node horizontallyTikZ: What EXACTLY does the the |- notation for...