標題包與 Threeparttablex 包不相容?

標題包與 Threeparttablex 包不相容?

我正在嘗試完成這樣的事情: 帶有超連結的表中的腳註

除了使用標題包之外,我還需要它來做其他事情。這兩種方法似乎並不能很好地結合在一起,我似乎不知道如何解決它。我收到的警告如下:

包標題警告:輸入行 32 上\label沒有正確的內容\caption

並且引用無法解析(我在其位置上得到了可怕的 ?? )。如果我嘗試在條目\caption之前添加 a ,它基本上只是嘗試使用我的標題字體將多個標題添加到同一個表中。\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

套餐三部分錶負載三部分錶正如其他答案(包括問題連結的答案)所明確的那樣,當然可以使用它來自定義標準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

首先,這是不是captionthreeparttablex包之間不相容。該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(而不是1and 2),因為只有\item不帶可選參數的參數才會產生引用,因此兩者\label實際上都使用由不帶可選參數創建的相同引用\item

套件threeparttablex重新定義\itemtablenotes僅在內部),因此\item[2]將產生一個引用(透過定義\@currentlabel):[1]

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

Ups,2現在已經消失了。發生了什麼事?

好吧,\renewlist{tablenotes}{enumerate}{1}重新定義tablenotes環境以使用普通enumerate環境代替。正如我們從上面知道的,\item[2]在普通enumerate環境中根本不會產生供使用的引用,因此這消除了實際上會產生引用\label的功能。因此,現在將選擇參考,而不是由最後一個產生參考的命令產生的參考。但沒有任何內容,因此輸出只是空的。添加 a演示了這一點: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內沒有正確引用的情況。figuretablethreeparttable

但是:我承認該軟體包提供的警告訊息內容caption在這裡具有誤導性。我選擇文字“\label withoutproperty\caption”,因為\label沒有前導\caption通常是這裡的問題。我將在下一個版本中將其更改為技術上更正確的文字“\沒有正確引用的標籤”。

[1] 這是該套件的記錄功能threeparttablex:「透過使用套件選項»referable«,我們將更改一些三部分錶內部結構,以便(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}

在此輸入影像描述

相關內容