TeX - LaTeX Asked by Alessandro Zunino on August 27, 2020
Look at this piece of paper from an APS journal:
as you can see there is a single image (called figure 3) with already embedded the (a), (b), etc.. letters indicating different parts of the same figure.
If you look above it you can see they are able to reference the single parts of the figure (e.g. fig. 3(b)), but how is possible to do that since they don’t have subfigures? My guessing was they were using phantom captions from the subcaption package, but this is not possible since this latter is not compatible with REVTeX 4.2 (that is the standard document package for APS journals). My question is: how can I obtain the same result?
Here you can find a Minimal Working Example of my attempt:
documentclass{revtex4-2}
usepackage[colorlinks,linkcolor=red,citecolor=red,urlcolor=red]{hyperref}
usepackage[demo]{graphicx}
begin{document}
begin{figure}
centering
includegraphics[width=textwidth]{example-image-a}
caption{Main caption here}
label{fig:main}
end{figure}
Suppose that figure ref{fig:main} is already divided in part (a) and part (b). I want to reference part ref{fig:main}a and part ref{fig:main}b, but if I do like this only the number is textit{clickable}, not the letter. Moreover I have to write manually the letter. A workaround I have found is hyperref[fig:main]{ref{fig:main}a}, but I am still not satisfied because I still have to write the letter manually.
end{document}
Note that I only have REVTex4-1, I however assume the solution works also for REVTex4-2.
I achieved the results using a hacky tikz solution. We use tikz to draw over the original plot. As subcaption is not available for REVTex, we use an empty subfig.
We first make an environment:
newenvironment{captivy}[1]{%SETUP
begin{tikzpicture}[every node/.style={inner sep=0}]
node[anchor=south west,inner sep=0] (image) at (0,0) {#1};
begin{scope}[x={(image.south east)},y={(image.north west)}]
}%
{%TEARDOWN
end{scope}%
pgfresetboundingbox
path[use as bounding box] (image.south west) rectangle (image.north east);
end{tikzpicture}%
}
This includes our figure given as argument #1
on a tikz picture.
The last two lines in tikzpicture
are about the bounding box, that we don't create additional whitespace.
Next we create a command to creat captions within this environment:
newcommand*{oversubcaption}[3]{%
draw (#1) node[fill=white,inner sep=0pt, opacity=0.2, above, yscale=1.1, xscale=1.1] {phantom{(a)#2}};
draw (#1) node[inner sep=0pt, above]{%
subfloat[#2label{#3}]{phantom{(a)}}
% % subcaption{#2}label{#3}
};
}
As we cannot use subcaption
, we replaced it by subfloat
. We put the empty image phantom(a)
, and add the label argument #3
. Addtionally we can provide a caption #2
. The first argument #1
specifies the position of the caption and label.
(The first line adds a transparent background, you can omit it if you don't like it.)
The rest of the document would then be
documentclass{revtex4-1}
usepackage{tikz}
usepackage{graphicx}
usepackage[caption=false]{subfig}
usepackage[colorlinks,linkcolor=red,citecolor=red,urlcolor=red]{hyperref}
begin{document}
begin{figure}
centering
begin{captivy}{includegraphics[width=.5textwidth]{example-image-a}}
oversubcaption{0.2, 0.9}{}{fig:suba}
oversubcaption{0.7, 0.9}{}{fig:subb}
end{captivy}
caption{Main caption here}
label{fig:main}
end{figure}
Suppose that figure ref{fig:main} is already divided in part subref{fig:suba} and part subref{fig:subb}.
I want to reference part ref{fig:suba} and part ref{fig:subb}, but if I do like this only the number is textit{clickable}, not the letter.
Moreover I have to write manually the letter.
A workaround I have found is hyperref[fig:main]{ref{fig:main}a}, but I am still not satisfied because I still have to write the letter manually.
end{document}
Correct answer by DerWeh on August 27, 2020
documentclass{revtex4-2}
usepackage{tabularx}
usepackage[labelformat=simple]{subcaption}
renewcommandthesubfigure{(alph{subfigure})}
usepackage{graphicx}
begin{document}
begin{figure}[htb]
captionsetup[subfigure]{singlelinecheck=off}
begin{tabularx}{linewidth}{*{3}{X}}
begin{subfigure}[b]{linewidth}
caption{}label{subfig:a}
includegraphics[width=linewidth]{example-image-duck}
end{subfigure}
&
begin{subfigure}[b]{linewidth}
caption{}label{subfig:b}
includegraphics[width=linewidth]{example-image-duck}
end{subfigure}
&
begin{subfigure}[b]{linewidth}
caption{}label{subfig:b}
includegraphics[width=linewidth]{example-image-duck}
end{subfigure}
coordinate image & coordinate image & coordinate image
type & type & type
end{tabularx}
caption{some long text}
label{fig:a}
end{figure}
see ref{subfig:a}
end{document}
gives
note: since you not provide mwe, i didn't bother with table looks. i focused only on your question. coloring and lines you can add yourself.
Answered by Zarko on August 27, 2020
Here is an elegant solution I have found. It produces the output as in the example provided as the desired output.
documentclass{revtex4-2}
usepackage[colorlinks,linkcolor=red,citecolor=red,urlcolor=red]{hyperref}
usepackage[demo]{graphicx}
usepackage[capitalize]{cleveref}
% usepackage{subcaption} % Incompatible with revtex4-2
usepackage[caption=false]{subfig}
% Keep the parentheses like in subref but allow to use cleveref
captionsetup[subfigure]{subrefformat=simple,labelformat=simple,listofformat=subsimple}
renewcommandthesubfigure{(alph{subfigure})}
% Allows referencing phantom subfigures, i.e. when (a), (b) are part of an
% image itself. Must be followed by vspace{-2baselineskip}
newcommand{phantomsubfloat}[1]{
{% apply caption setup only temporarily
captionsetup[subfigure]{labelformat=empty}
subfloat[][]{#1}
}%
}
begin{document}
begin{figure}
centering
includegraphics[width=textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
phantomsubfloat{label{fig:main_spaced_a}}
phantomsubfloat{label{fig:main_spaced_b}}
phantomsubfloat{label{fig:main_spaced_c}}
caption{
Using empty subfloat gets half the job done, but there is too much space between the image and the main caption
label{fig:main_spaced}
}
end{figure}
begin{figure}
centering
includegraphics[width=textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
phantomsubfloat{label{fig:main_a}}
phantomsubfloat{label{fig:main_b}}
phantomsubfloat{label{fig:main_c}}
vspace{-2baselineskip}% Remove extra line inserted by subfloat
caption{
But it can be elegantly removed!
label{fig:main}
}
end{figure}
begin{figure}
includegraphics[width=textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
phantomsubfloat{label{fig:justified_a}}
phantomsubfloat{label{fig:justified_b}}
phantomsubfloat{label{fig:justified_c}}
vspace{-2baselineskip}% Remove extra line inserted by subfloat
caption{
If caption centering is not desired you will find issues when trying to use the caption or subcaption packages (as several other solutions propose). But this solution keeps things elegant.
label{fig:justified}
}
end{figure}
You can now simply reference~cref{fig:main_a}. Cref{fig:main_a,fig:main_b,fig:main_c} can all be referenced now.
end{document}
Result:
Answered by caenrigen on August 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP