1

I want to place some code inside of an enumerate whose labels are encircled letters. I'm following this question to get the encircled letter labels, but I'm having a spacing issue:

\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{courier}

\lstset{basicstyle=\footnotesize\tt}

\begin{document}

\newcommand*\circlabel[1]{%
    \begin{tikzpicture}[baseline=(C.base)]
        \node[draw,circle,inner sep=1pt,minimum size=4ex](C) {#1};
    \end{tikzpicture}}

\begin{enumerate}[label=\protect\circlabel{$\Alph*$}]
    \item
        \begin{lstlisting}[language=Java,gobble=12]
            int someCode = 0;
            int onMultipleLines = 1;
            int likeThis = 2;
        \end{lstlisting}
\end{enumerate}

\end{document}

enter image description here

How do I get rid of the space between the first and second lines of code?

Jeff
  • 277

1 Answers1

2

One option would be to use the overlay option for the tikzpicure, so it doesn't take space and adjust labelsep:

\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{courier}

\lstset{basicstyle=\footnotesize\tt}

\begin{document}

\newcommand*\circlabel[1]{%
    \begin{tikzpicture}[baseline=(C.base),overlay]
        \node[draw,circle,inner sep=1pt,minimum size=4ex](C) {#1};
    \end{tikzpicture}}

\begin{enumerate}[label=\protect\circlabel{$\Alph*$},labelsep=15pt]
    \item
        \begin{lstlisting}[language=Java,gobble=12]
            int someCode = 0;
            int onMultipleLines = 1;
            int likeThis = 2;
        \end{lstlisting}
\end{enumerate}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thanks! I also added leftmargin=50pt to prevent the labels from spilling into the left page margin (since labelsep pushes the labels to the left, rather than pushing the content to the right). – Jeff Jan 16 '15 at 18:51