How can I hide a figure but keep its numbering? Announcing the arrival of Valued Associate...
When I export an AI 300x60 art board it saves with bigger dimensions
In search of the origins of term censor, I hit a dead end stuck with the greek term, to censor, λογοκρίνω
Israeli soda type drink
Coin Game with infinite paradox
My admission is revoked after accepting the admission offer
Why is arima in R one time step off?
Will I lose my paid in full property
Why I cannot instantiate a class whose constructor is private in a friend class?
Putting Ant-Man on house arrest
How to compute a Jacobian using polar coordinates?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Arriving in Atlanta (after US Preclearance in Dublin). Will I go through TSA security in Atlanta to transfer to a connecting flight?
Protagonist's race is hidden - should I reveal it?
Test if all elements of a Foldable are the same
Did war bonds have better investment alternatives during WWII?
Bright yellow or light yellow?
Where to find documentation for `whois` command options?
false 'Security alert' from Google - every login generates mails from 'no-reply@accounts.google.com'
Is there a way to fake a method response using Mock or Stubs?
Processing ADC conversion result: DMA vs Processor Registers
How to begin with a paragraph in latex
What does こした mean?
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?
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
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
|
show 1 more comment
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
if i correctly understood your question, than adding%beforeincludegraphicsis what you looking for. for examplebegin{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 havelabelinsidecaption?
– 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 thecaption? Should it still go to the LoF?
– Skillmon
Aug 30 '18 at 21:45
|
show 1 more comment
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
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
floats cross-referencing
asked Aug 30 '18 at 15:26
JPGJPG
1,532413
1,532413
if i correctly understood your question, than adding%beforeincludegraphicsis what you looking for. for examplebegin{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 havelabelinsidecaption?
– 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 thecaption? Should it still go to the LoF?
– Skillmon
Aug 30 '18 at 21:45
|
show 1 more comment
if i correctly understood your question, than adding%beforeincludegraphicsis what you looking for. for examplebegin{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 havelabelinsidecaption?
– 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 thecaption? 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
|
show 1 more comment
4 Answers
4
active
oldest
votes
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.

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.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 '18 at 17:12
Whygdefthelabelname? Wouldn't adefbe enough in case ofNewEnviron?
– Skillmon
Aug 30 '18 at 20:21
@Skillmon: Within thelrboxenvironment wherelabelis executed the first time, adefwould renderlabelnameundefined when usingoldlabel{labelname}.gdefmakes it available for use outside of thelrboxgroup.
– Werner
Aug 30 '18 at 20:23
@Werner forgot about thelrbox.
– Skillmon
Aug 30 '18 at 20:23
|
Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.

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}
Whyresizebox? You could as well just put the stuff inbox0and 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 ofbox0before. How would you use it in this context?
– Milo
Aug 30 '18 at 16:03
I managed to obtain your output by changingresizebox{!}{0cm}toresizebox{!}{0.000001cm}; strange that it doesn't work with0cm...
– JPG
Aug 30 '18 at 16:19
Something likesetbox0hbox{...}. The 0 box register is often used for temporary stuff (e.g. bysmashand the like). Stuff which is typed in asetboxis fully evaluated and stored in the specified box register, but not output (you can then output it byunhboxin case of ahbox, orunvboxforvbox; there are other methods of outputting them, the simplest beingbox, all of the aforementioned require you to specify a box register, e.g. 0 or the name of anewboxornewsavebox, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 '18 at 20:16
|
show 1 more comment
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}

|
Simple but works: Comment out the includegraphics command.
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.
|
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.

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.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 '18 at 17:12
Whygdefthelabelname? Wouldn't adefbe enough in case ofNewEnviron?
– Skillmon
Aug 30 '18 at 20:21
@Skillmon: Within thelrboxenvironment wherelabelis executed the first time, adefwould renderlabelnameundefined when usingoldlabel{labelname}.gdefmakes it available for use outside of thelrboxgroup.
– Werner
Aug 30 '18 at 20:23
@Werner forgot about thelrbox.
– Skillmon
Aug 30 '18 at 20:23
|
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.

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.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 '18 at 17:12
Whygdefthelabelname? Wouldn't adefbe enough in case ofNewEnviron?
– Skillmon
Aug 30 '18 at 20:21
@Skillmon: Within thelrboxenvironment wherelabelis executed the first time, adefwould renderlabelnameundefined when usingoldlabel{labelname}.gdefmakes it available for use outside of thelrboxgroup.
– Werner
Aug 30 '18 at 20:23
@Werner forgot about thelrbox.
– Skillmon
Aug 30 '18 at 20:23
|
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.

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.
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.

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.
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
Whygdefthelabelname? Wouldn't adefbe enough in case ofNewEnviron?
– Skillmon
Aug 30 '18 at 20:21
@Skillmon: Within thelrboxenvironment wherelabelis executed the first time, adefwould renderlabelnameundefined when usingoldlabel{labelname}.gdefmakes it available for use outside of thelrboxgroup.
– Werner
Aug 30 '18 at 20:23
@Werner forgot about thelrbox.
– Skillmon
Aug 30 '18 at 20:23
|
It works well and is easy to implement. Thanks.
– JPG
Aug 30 '18 at 17:12
Whygdefthelabelname? Wouldn't adefbe enough in case ofNewEnviron?
– Skillmon
Aug 30 '18 at 20:21
@Skillmon: Within thelrboxenvironment wherelabelis executed the first time, adefwould renderlabelnameundefined when usingoldlabel{labelname}.gdefmakes it available for use outside of thelrboxgroup.
– Werner
Aug 30 '18 at 20:23
@Werner forgot about thelrbox.
– 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
|
Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.

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}
Whyresizebox? You could as well just put the stuff inbox0and 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 ofbox0before. How would you use it in this context?
– Milo
Aug 30 '18 at 16:03
I managed to obtain your output by changingresizebox{!}{0cm}toresizebox{!}{0.000001cm}; strange that it doesn't work with0cm...
– JPG
Aug 30 '18 at 16:19
Something likesetbox0hbox{...}. The 0 box register is often used for temporary stuff (e.g. bysmashand the like). Stuff which is typed in asetboxis fully evaluated and stored in the specified box register, but not output (you can then output it byunhboxin case of ahbox, orunvboxforvbox; there are other methods of outputting them, the simplest beingbox, all of the aforementioned require you to specify a box register, e.g. 0 or the name of anewboxornewsavebox, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 '18 at 20:16
|
show 1 more comment
Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.

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}
Whyresizebox? You could as well just put the stuff inbox0and 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 ofbox0before. How would you use it in this context?
– Milo
Aug 30 '18 at 16:03
I managed to obtain your output by changingresizebox{!}{0cm}toresizebox{!}{0.000001cm}; strange that it doesn't work with0cm...
– JPG
Aug 30 '18 at 16:19
Something likesetbox0hbox{...}. The 0 box register is often used for temporary stuff (e.g. bysmashand the like). Stuff which is typed in asetboxis fully evaluated and stored in the specified box register, but not output (you can then output it byunhboxin case of ahbox, orunvboxforvbox; there are other methods of outputting them, the simplest beingbox, all of the aforementioned require you to specify a box register, e.g. 0 or the name of anewboxornewsavebox, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 '18 at 20:16
|
show 1 more comment
Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.

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}
Is this what you are looking for? Using resizebox and minipage you can make the includegraphics and caption have zero height.

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}
edited Aug 30 '18 at 16:04
answered Aug 30 '18 at 15:53
MiloMilo
6,85721951
6,85721951
Whyresizebox? You could as well just put the stuff inbox0and 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 ofbox0before. How would you use it in this context?
– Milo
Aug 30 '18 at 16:03
I managed to obtain your output by changingresizebox{!}{0cm}toresizebox{!}{0.000001cm}; strange that it doesn't work with0cm...
– JPG
Aug 30 '18 at 16:19
Something likesetbox0hbox{...}. The 0 box register is often used for temporary stuff (e.g. bysmashand the like). Stuff which is typed in asetboxis fully evaluated and stored in the specified box register, but not output (you can then output it byunhboxin case of ahbox, orunvboxforvbox; there are other methods of outputting them, the simplest beingbox, all of the aforementioned require you to specify a box register, e.g. 0 or the name of anewboxornewsavebox, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 '18 at 20:16
|
show 1 more comment
Whyresizebox? You could as well just put the stuff inbox0and 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 ofbox0before. How would you use it in this context?
– Milo
Aug 30 '18 at 16:03
I managed to obtain your output by changingresizebox{!}{0cm}toresizebox{!}{0.000001cm}; strange that it doesn't work with0cm...
– JPG
Aug 30 '18 at 16:19
Something likesetbox0hbox{...}. The 0 box register is often used for temporary stuff (e.g. bysmashand the like). Stuff which is typed in asetboxis fully evaluated and stored in the specified box register, but not output (you can then output it byunhboxin case of ahbox, orunvboxforvbox; there are other methods of outputting them, the simplest beingbox, all of the aforementioned require you to specify a box register, e.g. 0 or the name of anewboxornewsavebox, 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
|
show 1 more comment
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}

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

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

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}

answered Aug 30 '18 at 21:52
SkillmonSkillmon
24.4k12250
24.4k12250
|
|
Simple but works: Comment out the includegraphics command.
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.
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.
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.
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.
answered 17 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.
|
|
if i correctly understood your question, than adding
%beforeincludegraphicsis what you looking for. for examplebegin{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
labelinsidecaption?– 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