仅在表环境中重新定义 cite 命令

仅在表环境中重新定义 cite 命令

我正在使用 natbib 包对论文报告进行引用:

\usepackage[authoryear,sort,round]{natbib}
\bibliographystyle{apa}

引用应该是作者年份,文中带括号,并且排序,这对我来说非常完美。

问题是,我的表格环境中的列非常大,包含大量引用。即使我使用自定义列,在表格中保留作者年份样式也很难用文本宽度来排列表格宽度。

%ltxtable configuration
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} % flush-left, while allowing hyphenation
\newcolumntype{C}{>{\Centering\arraybackslash}X} % centered, while allowing hyphenation
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

我需要重新定义 cite 命令,使其使用括号编号,而不是仅在表格环境中使用作者样式。此外,我希望括号为上标,我已经找到了解决方案,但它始终是作者年份样式:

\usepackage{letltxmacro}

\LetLtxMacro{\originalcite}{\cite}
\def\tablecite#1#{%
  \def\pretablecite{#1}%
  \tableciteaux}
\def\tableciteaux#1{%
  \textsuperscript{\expandafter\originalcite\pretablecite{#1}}%
}
\AtBeginEnvironment{table}{\let\cite\tablecite}

这是我的文档(所需的最少代码)的样子:

\documentclass[12pt,fleqn,a4paper]{book} % Default font size and left-justified equations

\usepackage{etoolbox}

% Bibliography
\usepackage[authoryear,sort,round]{natbib}
\bibliographystyle{apa}%this one order the list of references whereas abbrvnat is the elsevier thing;

\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package
\usepackage{textcomp} % display ' apostrophe
\usepackage{dirtytalk} % access \say
\usepackage{longtable} %access longtable
\usepackage{lscape} %access landscape
\usepackage{pdflscape} % To rotate the page when using landscape & longtable
\usepackage{multirow} %access multirow
\usepackage{booktabs} %access \toprule & \bottomrule \cmidrule
\usepackage{changepage}%adjustwidth
\usepackage{ragged2e} % access \justify 
\usepackage{tabularx,ltxtable}
\usepackage{array}

%ltxtable configuration
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} % flush-left, while allowing hyphenation
\newcolumntype{C}{>{\Centering\arraybackslash}X} % centered, while allowing hyphenation
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

%To change the citation in the table environment 
\usepackage{letltxmacro}

\LetLtxMacro{\originalcite}{\cite}
\def\tablecite#1#{%
  \def\pretablecite{#1}%
  \tableciteaux}
\def\tableciteaux#1{%
  \textsuperscript{\expandafter\originalcite\pretablecite{#1}}%
}
\AtBeginEnvironment{table}{\let\cite\tablecite}

\begin{document}

\begingroup % restrict scope of reset of \textwidth parameter
\setlength\textwidth\textheight
\setlength\tabcolsep{1.25pt}
\begin{table}
\footnotesize
\renewcommand{\arraystretch}{1}%to keep the consistency and got similar render as longtable
\centering
\begin{tabular}{P{3.5cm}P{6cm}P{10cm}}
\toprule
\textbf{C1} & \textbf{C2} & \textbf{C3}\\
\midrule
DL.1. & C1.1. & reg \cite{cit1,cit2,cit3,cit4}, local \cite{cit1,cit2,cit3,cit4}, urban \cite{cit1,cit2,cit3,cit4}, rural \cite{cit1,cit2,cit3,cit4}\\
\phantom{C1} & C1.2. &pla \cite{cit1,cit2,cit3,cit4}, evaluation \cite{cit1,cit2,cit3,cit4}, frameworks \cite{cit1,cit2,cit3,cit4}\\
\phantom{C1} & C1.3. Envi&env and eco \cite{cit1,cit2,cit3,cit4}, lca \cite{cit1,cit2,cit3,cit4}\\
\phantom{C1} & C1.4. evaluation and assessment&investments \cite{cit1,cit2,cit3,cit4}, assessment ms \cite{cit1,cit2,cit3,cit4}, options \cite{cit1,cit2,cit3,cit4}, alternatives \cite{cit1,cit2,cit3,cit4}, plants \cite{cit1,cit2,cit3,cit4}, scenarios \cite{cit1,cit2,cit3,cit4}, production pathways\cite{cit1,cit2,cit3,cit4}\\
\phantom{C1} & C1.5. Site &projects \cite{cit1,cit2,cit3,cit4}, plants \cite{cit1,cit2,cit3,cit4}, stations \cite{cit1,cit2,cit3,cit4}, farms \cite{cit1,cit2,cit3,cit4}\\
\bottomrule
\end{tabular}
\caption{Caption.}
\label{tab:examples}
\end{table}
\endgroup

\bibliography{bibliography}

\end{document}

相关内容