How can I hide a figure but keep its numbering?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure
enddocument
Then I would like to hide figure 1 from PDF output, but label figure1
should still work, and the second picture should still be numbered as 2. Is it possible?
I tried with the comment
environment but it does not work.
floats cross-referencing
 |Â
show 1 more comment
up vote
4
down vote
favorite
I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure
enddocument
Then I would like to hide figure 1 from PDF output, but label figure1
should still work, and the second picture should still be numbered as 2. Is it possible?
I tried with the comment
environment but it does not work.
floats cross-referencing
if i correctly understood your question, than adding%
beforeincludegraphics
is what you looking for. for examplebeginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
@JPG: Do you always havelabel
insidecaption
?
– Werner
Aug 30 at 16:18
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
What should happen to thecaption
? Should it still go to the LoF?
– Skillmon
Aug 30 at 21:45
 |Â
show 1 more comment
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have a document with many figures; I want to print a short version of it with some figures hidden, but I would like that the global numbering of figures remain the same, and that labels still works. Here is a MWE:
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure
enddocument
Then I would like to hide figure 1 from PDF output, but label figure1
should still work, and the second picture should still be numbered as 2. Is it possible?
I tried with the comment
environment but it does not work.
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:
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure1.jpg
captionlabelfigure1
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]figure2.jpg
captionlabelfigure2
endfigure
enddocument
Then I would like to hide figure 1 from PDF output, but label figure1
should still work, and the second picture should still be numbered as 2. Is it possible?
I tried with the comment
environment but it does not work.
floats cross-referencing
asked Aug 30 at 15:26
JPG
72739
72739
if i correctly understood your question, than adding%
beforeincludegraphics
is what you looking for. for examplebeginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
@JPG: Do you always havelabel
insidecaption
?
– Werner
Aug 30 at 16:18
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
What should happen to thecaption
? Should it still go to the LoF?
– Skillmon
Aug 30 at 21:45
 |Â
show 1 more comment
if i correctly understood your question, than adding%
beforeincludegraphics
is what you looking for. for examplebeginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
@JPG: Do you always havelabel
insidecaption
?
– Werner
Aug 30 at 16:18
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
What should happen to thecaption
? Should it still go to the LoF?
– Skillmon
Aug 30 at 21:45
if i correctly understood your question, than adding
%
before includegraphics
is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
if i correctly understood your question, than adding
%
before includegraphics
is what you looking for. for example beginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
@JPG: Do you always have
label
inside caption
?– Werner
Aug 30 at 16:18
@JPG: Do you always have
label
inside caption
?– Werner
Aug 30 at 16:18
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
What should happen to the
caption
? Should it still go to the LoF?– Skillmon
Aug 30 at 21:45
What should happen to the
caption
? Should it still go to the LoF?– Skillmon
Aug 30 at 21:45
 |Â
show 1 more comment
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure
together with hidefigurestrue
to hide them, or hidefiguresfalse
(the default) to keep them in the document.
documentclassarticle
usepackagegraphicx,environ
newsaveboxfigsavebox% Box to capture figure content
newififhidefigures % Conditional to hide figures or keep them in the document
NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi
begindocument
hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)
Figure reffigure1 shows ldots
beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure
enddocument
Capturing the entire conditionalfigure
contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Whygdef
thelabelname
? Wouldn't adef
be enough in case ofNewEnviron
?
– Skillmon
Aug 30 at 20:21
@Skillmon: Within thelrbox
environment wherelabel
is executed the first time, adef
would renderlabelname
undefined when usingoldlabellabelname
.gdef
makes it available for use outside of thelrbox
group.
– Werner
Aug 30 at 20:23
@Werner forgot about thelrbox
.
– Skillmon
Aug 30 at 20:23
add a comment |Â
up vote
3
down vote
Is this what you are looking for? Using resizebox
and minipage
you can make the includegraphics
and caption
have zero height.
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure
enddocument
Whyresizebox
? You could as well just put the stuff inbox0
and never output it.
– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard ofbox0
before. How would you use it in this context?
– Milo
Aug 30 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 at 16:19
Something likesetbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. bysmash
and the like). Stuff which is typed in asetbox
is fully evaluated and stored in the specified box register, but not output (you can then output it byunhbox
in case of ahbox
, orunvbox
forvbox
; 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 anewbox
ornewsavebox
, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 at 20:16
 |Â
show 1 more comment
up vote
1
down vote
If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite
part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.
documentclassarticle
usepackagegraphicx
newififhidefigures
makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start
%
conditionalfigure@finish
makeatother
begindocument
listoffigures
Figure reffigure1 shows ldots
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure
together with hidefigurestrue
to hide them, or hidefiguresfalse
(the default) to keep them in the document.
documentclassarticle
usepackagegraphicx,environ
newsaveboxfigsavebox% Box to capture figure content
newififhidefigures % Conditional to hide figures or keep them in the document
NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi
begindocument
hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)
Figure reffigure1 shows ldots
beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure
enddocument
Capturing the entire conditionalfigure
contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Whygdef
thelabelname
? Wouldn't adef
be enough in case ofNewEnviron
?
– Skillmon
Aug 30 at 20:21
@Skillmon: Within thelrbox
environment wherelabel
is executed the first time, adef
would renderlabelname
undefined when usingoldlabellabelname
.gdef
makes it available for use outside of thelrbox
group.
– Werner
Aug 30 at 20:23
@Werner forgot about thelrbox
.
– Skillmon
Aug 30 at 20:23
add a comment |Â
up vote
4
down vote
accepted
It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure
together with hidefigurestrue
to hide them, or hidefiguresfalse
(the default) to keep them in the document.
documentclassarticle
usepackagegraphicx,environ
newsaveboxfigsavebox% Box to capture figure content
newififhidefigures % Conditional to hide figures or keep them in the document
NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi
begindocument
hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)
Figure reffigure1 shows ldots
beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure
enddocument
Capturing the entire conditionalfigure
contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Whygdef
thelabelname
? Wouldn't adef
be enough in case ofNewEnviron
?
– Skillmon
Aug 30 at 20:21
@Skillmon: Within thelrbox
environment wherelabel
is executed the first time, adef
would renderlabelname
undefined when usingoldlabellabelname
.gdef
makes it available for use outside of thelrbox
group.
– Werner
Aug 30 at 20:23
@Werner forgot about thelrbox
.
– Skillmon
Aug 30 at 20:23
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
It would be best to put these possibly-invisible figures inside their own environment. That way you can control how they are managed. Below I suggest something like conditionalfigure
together with hidefigurestrue
to hide them, or hidefiguresfalse
(the default) to keep them in the document.
documentclassarticle
usepackagegraphicx,environ
newsaveboxfigsavebox% Box to capture figure content
newififhidefigures % Conditional to hide figures or keep them in the document
NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi
begindocument
hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)
Figure reffigure1 shows ldots
beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure
enddocument
Capturing the entire conditionalfigure
contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.
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.
documentclassarticle
usepackagegraphicx,environ
newsaveboxfigsavebox% Box to capture figure content
newififhidefigures % Conditional to hide figures or keep them in the document
NewEnvironconditionalfigure[1][ht]%
ifhidefigures
% Hide this figure
letoldlabellabel
renewcommandlabel[1]gdeflabelname##1% Store label name
renewcommandcaption[1]##1% Make caption just print its argument
beginlrboxfigsavebox
BODY % Capture enture figure body
endlrbox
refstepcounterfigureoldlabellabelname% Step counter with reference and mark with label
else
% Traditional figure environment
beginfigure[#1]
BODY
endfigure
fi
begindocument
hidefigurestrue % Remove conditional figures from document
%hidefiguresfalse % Keep conditional figures in document (default)
Figure reffigure1 shows ldots
beginconditionalfigure[ht]
centering
includegraphics[width=5cm]example-image-a
captionlabelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
captionlabelfigure2
endfigure
enddocument
Capturing the entire conditionalfigure
contents ensures that it doesn't impede with the placement of floats within the document, otherwise the "invisible" float may still take up space above/below it.
answered Aug 30 at 16:50


Werner
420k579131577
420k579131577
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Whygdef
thelabelname
? Wouldn't adef
be enough in case ofNewEnviron
?
– Skillmon
Aug 30 at 20:21
@Skillmon: Within thelrbox
environment wherelabel
is executed the first time, adef
would renderlabelname
undefined when usingoldlabellabelname
.gdef
makes it available for use outside of thelrbox
group.
– Werner
Aug 30 at 20:23
@Werner forgot about thelrbox
.
– Skillmon
Aug 30 at 20:23
add a comment |Â
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Whygdef
thelabelname
? Wouldn't adef
be enough in case ofNewEnviron
?
– Skillmon
Aug 30 at 20:21
@Skillmon: Within thelrbox
environment wherelabel
is executed the first time, adef
would renderlabelname
undefined when usingoldlabellabelname
.gdef
makes it available for use outside of thelrbox
group.
– Werner
Aug 30 at 20:23
@Werner forgot about thelrbox
.
– Skillmon
Aug 30 at 20:23
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
It works well and is easy to implement. Thanks.
– JPG
Aug 30 at 17:12
Why
gdef
the labelname
? Wouldn't a def
be enough in case of NewEnviron
?– Skillmon
Aug 30 at 20:21
Why
gdef
the labelname
? Wouldn't a def
be enough in case of NewEnviron
?– Skillmon
Aug 30 at 20:21
@Skillmon: Within the
lrbox
environment where label
is executed the first time, a def
would render labelname
undefined when using oldlabellabelname
. gdef
makes it available for use outside of the lrbox
group.– Werner
Aug 30 at 20:23
@Skillmon: Within the
lrbox
environment where label
is executed the first time, a def
would render labelname
undefined when using oldlabellabelname
. gdef
makes it available for use outside of the lrbox
group.– Werner
Aug 30 at 20:23
@Werner forgot about the
lrbox
.– Skillmon
Aug 30 at 20:23
@Werner forgot about the
lrbox
.– Skillmon
Aug 30 at 20:23
add a comment |Â
up vote
3
down vote
Is this what you are looking for? Using resizebox
and minipage
you can make the includegraphics
and caption
have zero height.
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure
enddocument
Whyresizebox
? You could as well just put the stuff inbox0
and never output it.
– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard ofbox0
before. How would you use it in this context?
– Milo
Aug 30 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 at 16:19
Something likesetbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. bysmash
and the like). Stuff which is typed in asetbox
is fully evaluated and stored in the specified box register, but not output (you can then output it byunhbox
in case of ahbox
, orunvbox
forvbox
; 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 anewbox
ornewsavebox
, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 at 20:16
 |Â
show 1 more comment
up vote
3
down vote
Is this what you are looking for? Using resizebox
and minipage
you can make the includegraphics
and caption
have zero height.
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure
enddocument
Whyresizebox
? You could as well just put the stuff inbox0
and never output it.
– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard ofbox0
before. How would you use it in this context?
– Milo
Aug 30 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 at 16:19
Something likesetbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. bysmash
and the like). Stuff which is typed in asetbox
is fully evaluated and stored in the specified box register, but not output (you can then output it byunhbox
in case of ahbox
, orunvbox
forvbox
; 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 anewbox
ornewsavebox
, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 at 20:16
 |Â
show 1 more comment
up vote
3
down vote
up vote
3
down vote
Is this what you are looking for? Using resizebox
and minipage
you can make the includegraphics
and caption
have zero height.
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure
enddocument
Is this what you are looking for? Using resizebox
and minipage
you can make the includegraphics
and caption
have zero height.
documentclassarticle
usepackagegraphicx
begindocument
Figure reffigure1 shows ldots
beginfigure[ht]
centering
resizebox!0cmbeginminipagetextwidth
includegraphics[width=5cm]example-image-a
caption
labelfigure1
endminipage
endfigure
Figure reffigure2 shows ldots
beginfigure[ht]
centering
includegraphics[width=5cm]example-image-b
caption
labelfigure2
endfigure
enddocument
edited Aug 30 at 16:04
answered Aug 30 at 15:53


Milo
5,51321345
5,51321345
Whyresizebox
? You could as well just put the stuff inbox0
and never output it.
– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard ofbox0
before. How would you use it in this context?
– Milo
Aug 30 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 at 16:19
Something likesetbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. bysmash
and the like). Stuff which is typed in asetbox
is fully evaluated and stored in the specified box register, but not output (you can then output it byunhbox
in case of ahbox
, orunvbox
forvbox
; 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 anewbox
ornewsavebox
, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 at 20:16
 |Â
show 1 more comment
Whyresizebox
? You could as well just put the stuff inbox0
and never output it.
– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard ofbox0
before. How would you use it in this context?
– Milo
Aug 30 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 at 16:19
Something likesetbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. bysmash
and the like). Stuff which is typed in asetbox
is fully evaluated and stored in the specified box register, but not output (you can then output it byunhbox
in case of ahbox
, orunvbox
forvbox
; 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 anewbox
ornewsavebox
, the latter being the LaTeX macro, the former TeX).
– Skillmon
Aug 30 at 20:16
Why
resizebox
? You could as well just put the stuff in box0
and never output it.– Skillmon
Aug 30 at 16:00
Why
resizebox
? You could as well just put the stuff in box0
and never output it.– Skillmon
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
Yes, your output is what I want, but it doesn't work on my computer, figure 1 is still visible with bad alignment.
– JPG
Aug 30 at 16:00
@Skillmon I've not heard of
box0
before. How would you use it in this context?– Milo
Aug 30 at 16:03
@Skillmon I've not heard of
box0
before. How would you use it in this context?– Milo
Aug 30 at 16:03
I managed to obtain your output by changing
resizebox!0cm
to resizebox!0.000001cm
; strange that it doesn't work with 0cm
...– JPG
Aug 30 at 16:19
I managed to obtain your output by changing
resizebox!0cm
to resizebox!0.000001cm
; strange that it doesn't work with 0cm
...– JPG
Aug 30 at 16:19
Something like
setbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. by smash
and the like). Stuff which is typed in a setbox
is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox
in case of a hbox
, or unvbox
for vbox
; there are other methods of outputting them, the simplest being box
, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox
or newsavebox
, the latter being the LaTeX macro, the former TeX).– Skillmon
Aug 30 at 20:16
Something like
setbox0hbox...
. The 0 box register is often used for temporary stuff (e.g. by smash
and the like). Stuff which is typed in a setbox
is fully evaluated and stored in the specified box register, but not output (you can then output it by unhbox
in case of a hbox
, or unvbox
for vbox
; there are other methods of outputting them, the simplest being box
, all of the aforementioned require you to specify a box register, e.g. 0 or the name of a newbox
or newsavebox
, the latter being the LaTeX macro, the former TeX).– Skillmon
Aug 30 at 20:16
 |Â
show 1 more comment
up vote
1
down vote
If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite
part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.
documentclassarticle
usepackagegraphicx
newififhidefigures
makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start
%
conditionalfigure@finish
makeatother
begindocument
listoffigures
Figure reffigure1 shows ldots
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument
add a comment |Â
up vote
1
down vote
If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite
part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.
documentclassarticle
usepackagegraphicx
newififhidefigures
makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start
%
conditionalfigure@finish
makeatother
begindocument
listoffigures
Figure reffigure1 shows ldots
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite
part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.
documentclassarticle
usepackagegraphicx
newififhidefigures
makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start
%
conditionalfigure@finish
makeatother
begindocument
listoffigures
Figure reffigure1 shows ldots
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument
If the caption should still produce an entry in the LoF, one could use the following (with kind help of @DavidCarlisle on the immediatewrite
part). The only problem is that if two floats happen to be on the same page and one of them is hidden, the order of the entries in the LoF might get swapped.
documentclassarticle
usepackagegraphicx
newififhidefigures
makeatletter
newenvironmentconditionalfigure[1]
%
ifhidefigures
letzzwrite
protecteddefwriteimmediatezz%
defconditionalfigure@start
%
def@captypefiguresetbox0vboxbgroupcolor@setgroup
%
defconditionalfigure@finish
%
color@endgroupegroup
%
else
ifrelaxdetokenize#1relax
defconditionalfigure@start
beginfigure%
else
defconditionalfigure@start
beginfigure[#1]%
fi
defconditionalfigure@finish
endfigure%
fi
conditionalfigure@start
%
conditionalfigure@finish
makeatother
begindocument
listoffigures
Figure reffigure1 shows ldots
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-duck
captionFigure 1labelfigure1
endconditionalfigure
Figure reffigure2 shows ldots
hidefigurestrue
beginconditionalfigure
centering
includegraphics[width=5cm]example-image-b
captionFigure 2labelfigure2
endconditionalfigure
enddocument
answered Aug 30 at 21:52


Skillmon
17.5k11535
17.5k11535
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
if i correctly understood your question, than adding
%
beforeincludegraphics
is what you looking for. for examplebeginfigure[ht] centering % includegraphics[width=5cm]figure1.jpg captionlabelfigure1 endfigure
– Zarko
Aug 30 at 16:01
Yes, but my goal is to have one version of my document, and by switching one option in the preamble, it would turn on/off some less important figures.
– JPG
Aug 30 at 16:04
@JPG: Do you always have
label
insidecaption
?– Werner
Aug 30 at 16:18
@Werner: Yes, always. And sometimes I have subfigures with labels for each one.
– JPG
Aug 30 at 16:20
What should happen to the
caption
? Should it still go to the LoF?– Skillmon
Aug 30 at 21:45