8

I use the acronym-package for my acronyms.

To create my List of Acronyms I have the following code in my main.tex:

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

and the acronyms.tex looks like:

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

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

The result is this: enter image description here

I really dislike the spaces between the acronyms and would prefer no line spacing, as in my List of Listings:

enter image description here

0

4 Answers 4

8

Since the acronym environment is really just a description environment, one possibility is to specify the itemsep of the acronym environment:

\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}

acronym

4
  • It would be nice if you could add a picture of what the output looks like :) Really adds to the quality of the answer, imo
    – Troy
    Apr 13, 2017 at 12:04
  • Adding only \itemsep did not work but you need the [JSONP]-parameter as well. I did not understand why, but people following this solution should watch for that.
    – tjati
    Apr 15, 2017 at 10:21
  • what exactly does the JSONP parameter stand for, here? Is it a coincidence that it matches one of the acronyms?
    – Clashsoft
    Apr 25, 2020 at 13:57
  • I figured out that the environment parameter ([JSONP]) is supposed to be the longest acronym used, as per the acronym pdf manual. It ensures they are aligned.
    – Clashsoft
    Apr 25, 2020 at 14:03
5

The environment to patch is called AC@deflist, which we want to add \setlength{\itemsep}{0pt} to.

\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}

enter image description here

2
  • I needed the patch environment to get single spacing; just \itemsep did not work
    – MilleCodex
    Nov 20, 2023 at 1:49
  • @MilleCodex If you want to switch from double to single spacing, yes.
    – egreg
    Nov 20, 2023 at 9:01
3

Internally acronym uses description. So you can either (1) redefine acronym using your own list structure, or (2) just before acronym redefine description. Here is the second approach. I've added \itemsep0pt\parsep0pt to the standard definition of description.

\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}

enter image description here

UPDATE When perpage option is used, the package adds an extra \\, probably a bug. So in this case we need to redefine the way package prints the items as well:

\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}

enter image description here

1

I know this is already a few years old. However, I just had the same issue and found a simpler solution I want to share.

When defining the list of acronyms like in the question:

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

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

Simply add the longest acronym in square brackets after the begin-statement like this:

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

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

Yeah, that's all, \itemsep0pt is just necessary if you need custom line spacing.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .