在特定引用後插入垂直空格 (bibtex)

在特定引用後插入垂直空格 (bibtex)

我想使用 BibTeX 在參考文獻部分的特定參考文獻之後插入一些垂直空格,最好使用一系列命令,例如:

\cite{ABC-2001} 
\refvspace{1cm} 
\cite{XYZ-2002}

參考文獻是用 導入的\bibliography{references.bib}。順序按照引用順序。參考書目風格是一種自訂風格,但我們可以說這是\bibliographystyle{unsrt}為了明確。

如何在不修改 bib 檔案的情況下做到這一點?

一個可能的起點:

\documentclass{article}
\begin{filecontents}{refs.bib}
@misc{P, author = {P}, year = {2001}}
@misc{Q, author = {Q}, year = {2002}}
@misc{A, author = {A}, year = {2001}}
@misc{B, author = {B}, year = {2002}}
\end{filecontents}

\begin{document}
    This is a survey on different topics.

    \section*{Topic 1}

    Text \cite{P}. Text \cite{Q}.

    \section*{Topic 2}

    % TODO: Visually separate the two topics in the bibliography here

    Text \cite{A}. Text \cite{B}.

    \bibliographystyle{unsrt}
    \bibliography{refs}
\end{document}

答案1

讓我們考慮一下您的輸入:

\cite{ABC-2001} 
\refvspace{1cm} 
\cite{XYZ-2002}

我們可以指派一些\vspace與 的參考相關聯的巨集XYZ-2002。也就是說,\vspace{1cm}一旦\bibitem{XYZ-2002}在參考書目中找到就調用。

下面的最小範例實現了這一點:

在此輸入影像描述

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{refs.bib}
@misc{P, author = {P}, year = {2001}}
@misc{Q, author = {Q}, year = {2002}}
@misc{A, author = {A}, year = {2001}}
@misc{B, author = {B}, year = {2002}}
\end{filecontents}

\makeatletter
\let\@refvspace\relax
\providecommand{\refvspace}[1]{%
  \gdef\@refvspace{#1}% Store \refvspace
}
\let\old@cite\cite% Store \cite in \old@cite
\renewcommand{\cite}[1]{%
  \ifx\@refvspace\relax
    % No \refvspace was used
  \else
    \begingroup
    % Create vspace macro
    \edef\x{\endgroup
      \noexpand\global\noexpand\@namedef{#1@vspace}{\noexpand\vspace{\@refvspace}}}\x
    \global\let\@refvspace\relax
  \fi
  \old@cite{#1}}% Process regular \cite
\let\old@bibitem\bibitem% Store \bibitem in \old@bibitem
\renewcommand{\bibitem}[1]{%
  \csname #1@vspace\endcsname% Insert \vspace macro
  \old@bibitem{#1}}% Process regular \bibitem
\makeatother

\begin{document}
This is a survey on different topics.

\section*{Topic 1}

Text \cite{P}. \refvspace{\baselineskip}Text \cite{Q}.

\section*{Topic 2}

\refvspace{1cm}

Text \cite{A}. Text \cite{B}.

\bibliographystyle{unsrt}
\bibliography{refs}

\end{document}

注意事項:

  • 上面的範例相當簡單,並且從\cite和中刪除了可選參數\bibitem。但是,如果需要的話可以恢復。

  • 內容不會寫入.bib.bbl,因此只有在以下情況下才有效\bibliography,因此僅在發生你所有的\refvspace宏。

相關內容