私は次のようなことを実現しようとしています: ハイパーリンク付きの表内の脚注
ただし、他の用途に必要なキャプション パッケージを一緒に使用する必要があります。この 2 つのアプローチはうまく噛み合わないようで、回避方法がわかりません。表示される警告は次のとおりです。
パッケージ キャプションの警告:入力行 32 に
\label
適切なキャプションがありません\caption
。説明については、キャプション パッケージのドキュメントを参照してください。
そして、参照は解決されません (代わりに恐ろしい ?? が表示されます)。エントリの前に を追加しようとすると、\caption
基本的には、キャプション フォントで同じテーブルに複数のキャプションを追加しようとするだけです。\label
\tnotex
\documentclass[letterpaper]{article}
% This package allows for footnoting within tables
\usepackage{enumitem,booktabs,cfr-lm}
\usepackage{tabularx}
\usepackage[referable]{threeparttablex}
\renewlist{tablenotes}{enumerate}{1}
\makeatletter
\setlist[tablenotes]{label=\tnote{\alph*}, ref=\alph*, itemsep=\z@, topsep=\z@skip, partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\footnotesize}}
\makeatother
\usepackage{caption}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3\tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}%
\end{document}
キャプション パッケージがなくても問題なく動作しますが、ドキュメント内のキャプションのフォントと色を設定するためにキャプション パッケージを使用しています。回避策を知っている人はいますか?
答え1
その包み3部構成の表x負荷3つの部分から成るテーブルまた、質問からリンクされている回答を含む他の回答からも明らかなように、などtablenotes
で使用するために標準環境をカスタマイズするために使用することは確かに可能であり、別の回答で示唆されているように、tabular
などで使用することに限定されません。longtable
実際、あなたのコードは、ほんの少し変更するだけで問題なく動作しますtablenotes
。自動列挙体を作成して、それをハードコードされたラベルで上書きします。これは意味がありません。推奨されない、ベストプラクティスではないアラビア数字をマーカーとして使用したい場合は、カスタマイズをtablenotes
適切に変更するだけです。
\setlist[tablenotes]{label=\tnote{\arabic*}, ref=\arabic*, itemsep=0pt, topsep=0pt, partopsep=0pt ,parsep=0pt, itemindent=0pt, labelindent=\tabcolsep, labelsep=.2em, leftmargin=*, align=left, before={\footnotesize}}
そして書く
\begin{tablenotes}
\item This is the first note.
\item \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
などと書くことを好む場合は、そもそも環境を\item[1]
再定義しないでください。tablenotes
これらの変更と の追加により\usepackage{hyperref}
、ハイパーリンクされたメモは正常に動作するようになりました。
完全なコード:
\documentclass[letterpaper]{article}
\usepackage{enumitem,cfr-lm}% you aren't using booktabs
\usepackage{tabularx}
\usepackage[referable]{threeparttablex}
\renewlist{tablenotes}{enumerate}{1}
\setlist[tablenotes]{label=\tnote{\arabic*}, ref=\arabic*, itemsep=0pt, topsep=0pt, partopsep=0pt ,parsep=0pt, itemindent=0pt, labelindent=\tabcolsep, labelsep=.2em, leftmargin=*, align=left, before={\footnotesize}}
\usepackage{hyperref}
\usepackage{caption}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3\tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item This is the first note.
\item \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
答え2
まず、これはないcaption
パッケージ間の非互換性threeparttablex
。caption
パッケージは、ここで何か問題が発生しているというヒントのみを提供し、これについては正しいです。
\item
しかし、まずはLaTeX2e 自体が提供するのデフォルト実装から始めましょう。
\def\@item[#1]{%
...
\if@noitemarg
\@noitemargfalse
\if@nmbrlist
\refstepcounter\@listctr
\fi
\fi
...}
ここでわかるように、リストが番号付きでオプションの引数なしで使用された場合にのみ、\item
参照(後で使用できます)が生成されます。特に、\ļabel
\item
\item[2]
ない\label
およびで使用できる参照を生成します\ref
。(これは、Leslie Lamport による設計上の決定のようです。)
サンプルドキュメント:
\documentclass{article}
\begin{document}
\ref{item1} \ref{item2}
\begin{enumerate}
\item \label{item1} Text
\item[2] \label{item2} Text
\end{enumerate}
\end{document}
オプション引数なしのみが参照を生成するため、ここでは両方とも\ref
出力されます1
( および ではありません1
) 2
。したがって、実際には両方とも、オプション引数なしによって作成された同じ参照を使用します。\item
\label
\item
パッケージは(内部のみ)threeparttablex
を再定義するので、(を定義することによって)参照を生成します。[1]\item
tablenotes
\item[2]
\@currentlabel
\renewcommand\tablenotes{%
\let\TPTL@item=\item
\renewcommand\item[1][]{\TPTL@item[##1]%
\phantomsection\protected@edef\@currentlabel{##1}}
...}
サンプルドキュメント:
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
結果は良好で、期待どおりに\tnotex{tn:2}
生成されます2
。(注: ここでパッケージの使用法をcaption
問題なく追加できます。)
\renewlist{tablenotes}
ここで、パッケージによって提供されるの使用法を追加しますenumitem
。
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\usepackage{enumitem}
\renewlist{tablenotes}{enumerate}{1}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
ああ、2
もう消えてしまった。何が起こったの?
さて、 は環境\renewlist{tablenotes}{enumerate}{1}
を再定義して、代わりにtablenotes
通常の環境を使用しますenumerate
。そして、上で説明したように、\item[2]
通常の環境内ではenumerate
の使用に対する参照は\label
まったく生成されないため、 が提供する機能が排除され、threeparttablex
実際\item[xxx]
に参照が生成されます。そのため、 は\label{tn:2}
代わりに、最後に生成されたコマンドによって生成された参照を選択します。しかし、参照は存在しないため、出力は単に空です。 を追加すると、\section
次のようになります。
\documentclass[letterpaper]{article}
\usepackage[referable]{threeparttablex}
\usepackage{enumitem}
\renewlist{tablenotes}{enumerate}{1}
\begin{document}
\section{Test} % <= This line added
\begin{table}[ht]
\centering
\begin{threeparttable}
\begin{tabular}{|l|c|c|}
\hline
A & 1 & 2 \tnote{1} \\
\hline
B & 2 & 1 \\
\hline
C & 3 \tnotex{tn:2} & 3 \\
\hline
Line & producing & space. \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] This is the first note.
\item[2] \label{tn:2} This is the hyperlinked note.
\end{tablenotes}
\end{threeparttable}
\caption{A table caption.}
\end{table}
\end{document}
ここで、 は(期待される ではなく)\tnotex{tn:2}
を生成します。これは、(まだ)が ではなく (最初の) セクションを指しているためです。1
2
\label{tn:2}
\item[2]
しかし、cfr が提供するサンプル ドキュメントが正しい出力を生成するのはなぜでしょうか。これは、\item
オプションの引数なしで を使用しているためです。また、上記からわかるように、これにより常に適切な参照が生成されます。
さて、話の最後の部分です。caption
パッケージはこれらすべてとどのような関係があるのでしょうか?
そうですね、パッケージには、、など内で適切な参照がないとcaption
検出する機能があります。そして、これがまさにここでの問題なので、この機能が影響します。\label
figure
table
threeparttable
しかし、パッケージによって提供される警告メッセージの内容は、ここでは誤解を招くものであることを認めます。先頭にcaption
a がない場合が通常問題となるため、私は「適切な \caption のない \label」というテキストを選択しました。次のバージョンでは、より技術的に正しい「適切な参照のない \label」というテキストに変更します。\label
\caption
[1] これはパッケージの文書化された機能ですthreeparttablex
: 「パッケージオプション»referable«を使用すると、いくつかのthreeparttable内部が変更され、(a) \item[...]によって発行された手動で指定されたノートマーカーが参照可能になり、...」 ( threeparttablex
2014年5月22日時点のドキュメントから引用)
答え3
私の回避策はおそらくあなたが探していたものとは正確には一致しないかもしれませんが、脚注のある表の場合、tabularx
環境を使用して、表の幅を指定して最後の列に脚注を配置するのが良い解決策だと思いますp
。また、表の幅全体を使用するには、脚注としてインライン列挙を使用することをお勧めします。マクロは、\tabref
参照の外観をカスタマイズするために使用されます。まとめると次のようになります。
\documentclass[letterpaper]{article}
\usepackage[inline]{enumitem}
\usepackage{booktabs,cfr-lm,tabularx,ragged2e}
\usepackage{caption,hyperref}
\captionsetup[table]{position=top,aboveskip=6pt}
\newcommand*{\tabref}[1]{\textsuperscript{\ref{#1}}}
\begin{document}
\begin{table}[ht]
\centering
\captionbox{A table caption made somewhat longer to see the
effect\label{tab:example}}{%
\begin{tabularx}{0.5\textwidth}{@{}c>{\hfil}X<{\hfil}c@{}}
\toprule
Line & producing & space \\
\midrule
A & 1 & 2\tabref{tn:1} \\
B & 2 & 1 \\
C & 3\tabref{tn:2} & 3 \\
\bottomrule
\multicolumn{3}{@{}p{0.5\textwidth}@{}}{\RaggedRight
\begin{enumerate*}
\item This is the first note.\label{tn:1}
\item This is the hyperlinked note\label{tn:2}.
\end{enumerate*}%
}%
\end{tabularx}%
}%
\end{table}
\end{document}