
在我的文件的一篇反思中,參考文獻按關鍵字分組。現在我想根據引文的類別列印每個部分的參考書目,例如一份帶有關鍵字的文章的參考書目in
和一份帶有關鍵字的參考書目out
。為了美觀,我希望參考書目連續編號,就像在這個文本模型中一樣
**In**
[1-1] a. “a”. In: a (a).
[1-2] c. “c”. In: c (c).
[1-3] e. “e”. In: e (e).
**Out**
[1-4] b. “b”. In: b (b).
[1-5] d. “d”. In: d (d).
因此,我使用defernumbers
ofbiblatex
對條目進行連續編號。問題是,這會導致每個 再次從 1 開始編號\printbibliography
。
我想defernumbers
跨\printbibliography
per啟用\refsection
。
微量元素
\documentclass{article}
\pagestyle{empty}
\usepackage{filecontents}
\begin{filecontents*}{test.bib}
@article{a,
title = {a},
author = {a},
journal = {a},
year = {a},
keywords = {in}
}
@article{b,
title = {b},
author = {b},
journal = {b},
year = {b},
keywords = {out}
}
@article{c,
title = {c},
author = {c},
journal = {c},
year = {c},
keywords = {in}
}
@article{d,
title = {d},
author = {d},
journal = {d},
year = {d},
keywords = {out}
}
@article{e,
title = {e},
author = {e},
journal = {e},
year = {e},
keywords = {in}
}
\end{filecontents*}
\usepackage[
defernumbers=true,
citestyle=numeric,
]{biblatex}
\defbibheading{subbibliography}[\bibname]{%
\subsubsection*{#1}
}
\addbibresource{test.bib}
\begin{document}
\section{Testing biblatex}
\refsection
\cite{a,b,c,d,e}
\printbibliography[
title={In},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=in
]
\printbibliography[
title={Out},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=out
]
\endrefsection
\section{Testing biblatex}
\refsection
\cite{a,b,c,d,e}
\printbibliography[
title={In},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=in
]
\printbibliography[
title={Out},
prefixnumbers={\thesection-},
heading=subbibliography,
keyword=out
]
\endrefsection
\end{document}
輸出
當然,還會有懸賞!
答案1
這個問題是由 的固有功能引起的biblatex
。從其他問題,具有在您用於向標籤添加前綴時應用的biblatex
隱式。這可以透過不同的方式解決,但只能透過真正稍微改變問題或改變前綴處理/應用方式的駭客。resetnumbers=true
prefixnumbers
由於這個問題的目的是按部分(或章節等)細分每個參考書目,因此可以以prefixnumber
不同的方式在全局應用該設置,從而消除resetnumbers=true
在每個參考書目中應用的隱式設置\printbibliography
。為此,我們重新定義了標籤的列印方式,並將其納入\thesection
格式中:
\DeclareFieldFormat{labelnumber}{\mkbibsecnum{#1}}
\newrobustcmd{\mkbibsecnum}[1]{\thesection-#1\relax}
每個標籤都儲存為 1、2、3...,但會使用列印時出現的部分編號進行格式化。 (注意*:因為我們以這種方式添加前綴,所以該\printbibliography
命令必須出現在與引文相同的section
/refsection
中。特別是,這意味著您不能使用此方法在末尾打印累積參考書目,其中多個refsection
s 細分為\printbibliography[section=1...]
)。
此時,剩下的就是使用 重置適當位置的編號(每個 的第一個參考書目refsection
)\printbibliography[...resetnumbers=true]
。
結果
結果顯示為:
微量元素
我做了一些更改,以使解決方案比原始 MWE 更有效。
refsection=section
(也可以是...=part
、...=chapter
等)全域傳遞到biblatex
僅收集每個部分中的參考。可依情況用\newrefsection
/替換\endrefsection
,以手動分區參考書目項目。
defernumbers=true
保留以按順序對每個子書目進行排序。
我還註解掉了一些引文,以強調編號和refsection
s 的效果。
修改後的 MWE 演示了該解決方案:
\documentclass{article}
\pagestyle{empty}
\usepackage{filecontents}
\begin{filecontents*}{test.bib}
@article{a,
title = {a},
author = {a},
journal = {a},
year = {a},
keywords = {in}
}
@article{b,
title = {b},
author = {b},
journal = {b},
year = {b},
keywords = {out}
}
@article{c,
title = {c},
author = {c},
journal = {c},
year = {c},
keywords = {in}
}
@article{d,
title = {d},
author = {d},
journal = {d},
year = {d},
keywords = {out}
}
@article{e,
title = {e},
author = {e},
journal = {e},
year = {e},
keywords = {in}
}
\end{filecontents*}
\usepackage[
defernumbers=true,
citestyle=numeric,
refsection=section % Each \section{...} starts a new refsection environment
]{biblatex}
% Format the labelnumber with \thesection prefix
\DeclareFieldFormat{labelnumber}{\mkbibsecnum{#1}}
\newrobustcmd{\mkbibsecnum}[1]{\thesection-#1\relax}
\defbibheading{subbibliography}[\bibname]{%
\subsubsection*{#1}
}
\addbibresource{test.bib}
\begin{document}
\section{Testing biblatex} % New refsection, too!
Cite a \cite{a};
Cite b \cite{b};
Cite c \cite{c};
\printbibliography[
title={In},
heading=subbibliography,
keyword=in,
resetnumbers=true % The first bibliography in each refsection needs its numbers manually reset
]
\printbibliography[
title={Out},
heading=subbibliography,
keyword=out
]
\section{Testing biblatex} % New refsection, too!
Cite b \cite{b};
Cite d \cite{d};
Cite e \cite{e}.
\printbibliography[
title={In},
heading=subbibliography,
keyword=in,
resetnumbers=true % The first bibliography in each refsection needs its numbers manually reset
]
\printbibliography[
title={Out},
heading=subbibliography,
keyword=out
]
\end{document}
*@Guido的解決方案重新定義整個參考書目環境,並使用枚舉系列計數器繼續對某些標籤進行計數,但不會對其他標籤進行計數。這可能適用於這個問題(並且可以解決累積參考書目的問題),但我無法按照OP要求的方式使用節編號來編譯程式碼。