
の文書化エンドフロートパッケージでは、マーカー内のテキストをデフォルトの「[表 3 について]」からカスタマイズする方法を説明していますが、ドキュメントの最後にある図へのハイパーリンクを含めるようにマーカーをカスタマイズしたいと思います。これはどのように実現できますか?
ここでサブ質問があります: マーカーをカスタマイズする場合、は図番号を参照します。図への参照を参照し、マーカー テキストを のようにすることができる\thepostfigure
類似のコマンドはありますか?\thefigurereference
Figure \ref{\thefigurereference}} about here.
アップデート2:コメントでは、バックリンクについても質問しました。これにより、ドキュメントの末尾にある図のキャプションが、テキストに埋め込まれた「[図 1 について]」フロートにハイパーリンクされます。@John Kormylo の承認されたソリューションはこれを実現します。
更新 1 [より明確にするために編集しました。これは @John Kormylo の元の回答を指しており、修正された回答ではありません]:
@John Kormylo の (元の) 解決策は機能しますが、サブキャプション パッケージと互換性がないことがわかりました。そのため、私の修正された質問は次のとおりです。キャプションでも機能する図へのハイパーリンク方法はありますか?
これは、ハイパーリンクが最後の図に移動しない、彼のソリューションを使用した MWE です。図 2 は、サブキャプションが必要な理由を示すためだけのものです。サブキャプションがなくても、subpcaption パッケージが使用されている限り、リンクは失敗します。
\documentclass{article}
\usepackage{endfloat}
\usepackage{mwe}
\usepackage{hyperref}
\usepackage{subcaption}
% John Kormylo's original solution, which works when the subcaption package isn't used:
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\hyperlink{#1.\csname thepost#1\endcsname}%
{[\csname #1name\endcsname~\csname thepost#1\endcsname\ about here.]}
\end{center}}
\begin{document}
\begin{figure}
\includegraphics{example-image}
\caption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\caption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}
生成されたファイルaux
から、解決策が機能しなかった理由は、サブキャプションによってカウンターの名前がなどから などfigure.1
に変更されることが示唆されています。表のリストには次の行があります (図へのハイパーリンクが機能しています)。figure.2
figure.caption.2
figure.caption.3
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces This is figure 1.\relax }}{3}{figure.caption.2}}
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces This is figure 2.\relax }}{4}{figure.caption.3}}
1 つの選択肢は、John Kormylo の (元の) コマンドを書き直して\floatplace
、番号付けを 2 から開始し、ヘッドの名前を または に変更するfigure.caption
ことですtable.caption
。しかし、別のドキュメントでは、figure.caption
aux ファイルの の番号付けは 18 から始まります。(ただし、これを MWE で再現する方法はまだわかりません。) つまり、このような回避策は役に立ちません。
答え1
は\caption
、という名前の\refstepcounter{figure}
を作成します。残念ながら、は(実際には)にしかアクセスできません。そのため、からへのマップを作成し、aux ファイルを介してそれをドキュメントの先頭に移動する必要があります。これとバックリンクを組み合わせるために、を に置き換えました。\hypertarget
\@currentHref
\floatplace
\thefigure
\thepostfigure
\thefigure
\@currentHref
\caption
\figurecaption
オリジナルに合わせて\floatplace
float 型に依存しないようにしました。ただし、\figurecaption
とのコードのみを追加しました\newfigure
。
\documentclass{article}
\usepackage{endfloat}
\usepackage{mwe}
\usepackage{subcaption}
\usepackage{hyperref}
\makeatletter
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\def\floatnumber{\csname thepost#1\endcsname}
\def\floatname{\csname #1name\endcsname}
\hypertarget{figureback\floatnumber}{}%
\@ifundefined{#1anchor\floatnumber}%
{[\floatname~\floatnumber\ about here.]}%
{\hyperlink{\csname #1anchor\floatnumber\endcsname}%
{[\floatname~\floatnumber\ about here.]}}
\end{center}}
\newcommand{\figurecaption}[2][\empty]% #1=short caption (optional), #2=caption
{\ifx\empty#1\relax \caption[#2]{\hyperlink{figureback\thefigure}{#2}}%
\else \caption[#1]{\hyperlink{figureback\thefigure}{#2}}%
\fi
\immediate\write\@auxout{\string\newfigure{\thefigure}{\@currentHref}}}
\makeatother
\newcommand{\newfigure}[2]% #1 = \thefigure, #2 = \@currentHref
{\expandafter\gdef\csname figureanchor#1\endcsname{#2}}
\begin{document}
\begin{figure}
\includegraphics{example-image}
\figurecaption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\figurecaption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}
これは、サブキャプションがどのような奇妙な命名規則を課しても機能するはずです。
答え2
表と図についても同じことを行う必要があり、同時に用語集パッケージのエラーをチェックする必要がありました。(どこかに独自の「tablecaption」関数が定義されていると思います。)
ここにそれがあります:
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{xcolor} %Farben
\usepackage{hyperref} %Links
\usepackage[nolists]{endfloat} % figures mit platzhalter und dann im Anhang
\renewcommand{\efloatseparator}{\mbox{}}
\usepackage{glossaries}
\usepackage{ifthen}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{mwe}
\makeatletter
\renewcommand{\floatplace}[1]{% #1 = float type (e.g. figure)
\begin{center}
\def\floatnumber{\csname thepost#1\endcsname}
\def\floatname{\csname #1name\endcsname}
\ifthenelse{\equal{#1}{figure}}% define backlink based on figure or table
{\def\backlink{figureback\floatnumber}}%
{\def\backlink{tableback\floatnumber}}%
\colorbox{yellow}{\floatname}
\colorbox{red}{\backlink}
\colorbox{orange}{\floatnumber}
\colorbox{green}{\csname #1anchor\floatnumber\endcsname}
\hypertarget{\backlink}{}
\@ifundefined{#1anchor\floatnumber}%
{[ \floatname~\floatnumber\ about here. ]}%
{[ \hyperlink{\csname #1anchor\floatnumber\endcsname}%
{\floatname~\floatnumber} about here. ]}
\end{center}
}
%for figure
\newcommand{\figurecaption}[2][\empty]% #1=short caption (optional), #2=caption
{%
\ifx\empty#1\relax %
\caption[#2]{\hyperlink{figureback\thefigure}{#2}}%
\else %
\caption[#1]{\hyperlink{figureback\thefigure}{#2}}%
\fi
\immediate\write\@auxout{\string\newfigure{\thefigure}{\@currentHref}}%
}
\makeatother
\newcommand{\newfigure}[2]% #1 = \thefigure, #2 = \@currentHref
{\expandafter\gdef\csname figureanchor#1\endcsname{#2}}
\makeatletter
%for table
\newcommand{\tabcaption}[2][\empty]% #1=short caption (optional), #2=caption (tabcaption instead of tablecaption for glossaries)
{%
\ifx\empty#1\relax %
\caption[#2]{\hyperlink{tableback\thetable}{#2}}%
\else %
\caption[#1]{\hyperlink{tableback\thetable}{#2}}%
\fi
\immediate\write\@auxout{\string\newtable{\thetable}{\@currentHref}}%
}
\makeatother
\newcommand{\newtable}[2]% #1 = \thetable, #2 = \@currentHref
{\expandafter\gdef\csname tableanchor#1\endcsname{#2}}
\begin{document}
\begin{table}
\tabcaption{tab}
\begin{tabular}{lcr}
1 & 2 & 3 \\
\end{tabular}
\end{table}
\begin{figure}
\includegraphics{example-image}
\figurecaption{A figure without subfigures}
\end{figure}
\begin{figure}[htb]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{first part}
\end{subfigure}%
%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=.9\textwidth]{example-image}
\caption{(second part)}
\end{subfigure}%
\figurecaption{A figure with subfigures}
\end{figure}
\lipsum[1-2]
\end{document}