引用報價環境

引用報價環境

目前我的 tex 檔案中有一個引用,如下所示:

\begin{quote}
blabla
\end{quote}

現在我想引用這段內聯引用。添加標籤有效,但我無法使其caption工作,以表明該引用實際上是數字 xy 因為此環境似乎不是浮動環境,這顯然是\caption{}.

所以我嘗試了以下方法:

\begin{quote}
blabla
\label{quote:one}
\end{quote}

並且\caption{test}在標籤之前添加行不通。

答案1

請參閱下文以了解替代外觀。請參閱附錄以了解使用 aux 檔案以允許將來引用的版本

正如克里斯蒂安在評論中指出的那樣,引用沒有計數器(因此沒有識別標籤)。然而,我們可以向環境引入一個標籤lquote,它需要一個標籤作為參數,可以透過 引用\quoteref

可以更改下面給出的實現,以適應引號、編號方案和外觀等的需要。

\documentclass{article}
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}%
  \expandafter\xdef\csname#1\endcsname{\fbox{\thenumquote}}%
  \quote``\ignorespaces}{\unskip''\fbox{\thenumquote}\endquote}
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.
\end{document}

在此輸入影像描述

替代外觀

\documentclass{article}
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}
  \expandafter\xdef\csname#1\endcsname{\thenumquote}%
  \quote Quote \thenumquote: ``\ignorespaces}{\unskip''\endquote}
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.
\end{document}

在此輸入影像描述

附錄:

從OP的評論看來,他可能\quoteref在環境中使用標籤定義先前的內容lquote。考慮到這一點,我在本附錄中實作了一個寫入 aux 檔案的系統,以使標籤在定義之前就可以使用。

\documentclass{article}
\makeatletter
\long\def \protected@iwrite#1#2#3{%
     \begingroup
     \let\thepage\relax
     #2%
     \let\protect\@unexpandable@protect
     \edef\reserved@a{\immediate\write#1{#3}}%
     \reserved@a
     \endgroup
     \if@nobreak\ifvmode\nobreak\fi\fi
    }
\newcounter{numquote}
\newenvironment{lquote}[1]{%
  \stepcounter{numquote}%
  \protected@iwrite\@auxout{\def\nex{\noexpand\noexpand\noexpand}}{%
    \nex\expandafter\xdef%
    \nex\csname #1%
    \nex\endcsname{\thenumquote}%
  }%
  \quote Quote \thenumquote: ``\ignorespaces}{\unskip''\endquote}
\makeatother
\newcommand\quoteref[1]{\csname#1\endcsname}
\begin{document}
In the future quotation \quoteref{quote:one}, 
  we see a difference from quote \quoteref{quote:two}.

Compare this quote
\begin{lquote}{quote:one}
blabla
\end{lquote}
to this one
\begin{lquote}{quote:two}
moreblabla
\end{lquote}
In quotation \quoteref{quote:one}, we see a difference from quote \quoteref{quote:two}.

\end{document}

在此輸入影像描述


注意:該\protected@iwrite巨集來自egreg的回答將 \\ 寫入文件

答案2

只有 a\pageref有意義:

\documentclass{article}
\usepackage{caption}
\begin{document}

\begingroup
\begin{quote}
    blabla
\end{quote} 
\captionof*{figure}{Test}\label{quote:one}
\endgroup

See quote on page~\pageref{quote:one}
\end{document}

答案3

公認的解決方案在許多方面都有缺陷。 LaTeX 已經有自己的引用機制,並且繞過它,這會導致您所看到的問題。

相反,我將lquote環境定義如下:

\newcounter{numquote}
\newenvironment{lquote}{%
  \refstepcounter{numquote}%
  \quote}{\unskip~\thenumquote\endquote}

你可以透過類似的方式使用它

\begin{lquote}
  blah blah
  \label{quote:one}
\end{lquote}
...
quote~\ref{quote:one}.

然後,如果你把

\usepackage{hyperref}

在序言的末尾,您將透過參考文獻中的超連結自動獲得所需的結果。

相關內容