無行距的首字母縮寫列表

無行距的首字母縮寫列表

我使用acronym-package 作為我的首字母縮寫。

為了建立我的縮寫列表,我在 main.tex 中有以下程式碼:

\usepackage[printonlyused, withpage]{acronym}
...
\section*{List of Acronyms}
\input{../assets/acronyms}

acronym.tex 看起來像:

\begin{acronym}
...
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}

  \acro{REST}{Representational State Transfer}
...
\end{acronym}

結果是這樣的: 在此輸入影像描述

我真的不喜歡首字母縮略詞之間的空格,並且希望沒有行間距,如我的列表中所示:

在此輸入影像描述

答案1

由於acronym環境實際上只是一個description環境,​​因此一種可能性是指定環境itemsepacronym

\documentclass{report}
\usepackage[withpage]{acronym}

\begin{document}

\tableofcontents

\section*{List of Acronyms}

\begin{acronym}[JSONP]\itemsep0pt %change this amount as desired
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}
  \acro{REST}{Representational State Transfer}
\end{acronym}

\section{Foo}

\ac{JSON} and \ac{JSONP}.

\section{Bar}

\ac{REST}.

\end{document}

縮寫詞

答案2

要修補的環境稱為AC@deflist,我們要加入\setlength{\itemsep}{0pt}其中。

\documentclass{report}
\usepackage[printonlyused,withpage]{acronym}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\AC@deflist}
  {\addtolength{\leftmargin}{\labelsep}}
  {\addtolength{\leftmargin}{\labelsep}\setlength{\itemsep}{0pt}}
  {}{}
\makeatother

\begin{document}

\tableofcontents

\section*{List of Acronyms}

\begin{acronym}[JSONP]
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}
  \acro{REST}{Representational State Transfer}
\end{acronym}

\section{Foo}

\ac{JSON} and \ac{JSONP}.

\section{Bar}

\ac{REST}.

\end{document}

在此輸入影像描述

答案3

內部acronym使用description.因此,您可以 (1) 使用您自己的清單結構重新定義,或 (2) 在重新定義acronym之前。這是第二種方法。我已經添加到的標準定義中。acronymdescription\itemsep0pt\parsep0ptdescription

\documentclass{article}

\usepackage{acronym}
\pagestyle{empty}
\begin{document}

\renewenvironment{description}
{\list{}{\labelwidth0pt\itemindent-\leftmargin
    \parsep0pt\itemsep0pt\let\makelabel\descriptionlabel}}
               {\endlist}
\begin{acronym}
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}
  \acro{REST}{Representational State Transfer}
\end{acronym}
\end{document}

在此輸入影像描述

更新perpage使用選項時,包會添加一個額外的\\,可能是一個錯誤。因此,在這種情況下,我們還需要重新定義 package 列印項目的方式:

\documentclass{article}
\usepackage[printonlyused, withpage]{acronym}
\pagestyle{empty}
\makeatletter
\def\AC@@acro#1[#2]#3{%
  \ifAC@nolist%
  \else%
  \ifAC@printonlyused%
    \expandafter\ifx\csname acused@#1\endcsname\AC@used%
       \item[\protect\AC@hypertarget{#1}{\aclabelfont{#2}}] #3%
          \ifAC@withpage%
            \expandafter\ifx\csname r@acro:#1\endcsname\relax%
               \PackageInfo{acronym}{%
                 Acronym #1 used in text but not spelled out in
                 full in text}%
            \else%
               \dotfill\pageref{acro:#1}% Sputious \\ deleted
            \fi
          \fi%
    \fi%
 \else%
    \item[\protect\AC@hypertarget{#1}{\aclabelfont{#2}}] #3%
 \fi%
 \fi%
 \begingroup
    \def\acroextra##1{}%
    \@bsphack
    \protected@write\@auxout{}%
       {\string\newacro{#1}[\string\AC@hyperlink{#1}{#2}]{#3}}%
    \@esphack
  \endgroup}
\makeatother

\begin{document}
We use \ac{JSON}, \ac{JSONP}, \ac{REST}.

\renewenvironment{description}
{\list{}{\labelwidth0pt\itemindent-\leftmargin
    \parsep0pt\itemsep0pt\let\makelabel\descriptionlabel}}
               {\endlist}
\begin{acronym}
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}

  \acro{REST}{Representational State Transfer}
\end{acronym}
\end{document}
 \documentclass{beamer}
    \usepackage{graphicx}
    \begin{document}

    \begin{figure}
    \begin{center}
    \input{tmp1.tex}
    \caption{Enter caption here}
    \label{Enter label here}
    \end{center}
    \end{figure}

  \end{document}

在此輸入影像描述

答案4

我知道這已經有幾年了。但是,我遇到了同樣的問題,並找到了一個更簡單的解決方案,我想分享。

在定義問題中的首字母縮寫列表時:

\begin{acronym}
...
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}

  \acro{REST}{Representational State Transfer}
...
\end{acronym}

只需在開始語句後面的方括號中加入最長的縮寫詞,如下所示:

\begin{acronym}[JSONP]
...
  \acro{JSON}{JavaScript Object Notation}
  \acro{JSONP}{JavaScript Object Notation with Padding}

  \acro{REST}{Representational State Transfer}
...
\end{acronym}

是的,僅此而已,\itemsep0pt如果您需要自訂行距,那麼這是必要的。

相關內容