Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wonder is it possible to highlight a number enclosing with an unfilled circle next to a line in a listing or table like the image below?

\documentclass[english,a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{changepage}

\begin{document}

\clearpage
\begin{table}[ht]
\begin{adjustwidth}{-3.7cm}{}
\begin{tabular}{|p{.6\textwidth}|p{.75\textwidth}|}
\hline
{\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={Java},
numbersep=18pt,numbers=left,xleftmargin=1.2cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
&
{\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={Java},
numbersep=16pt,
numbers=left,
xleftmargin=1cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
\\
\hline
\end{tabular}
\end{adjustwidth}
\caption{\label{fig:text}text experiment ent experiment experiment}
\end{table}
\end{document}

enter image description here

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

You can use the symbols defined in pifont package (see page 77, Table 254 of The Comprehensive LaTeX Symbol List).

Adding the option mathescape=true to your listing environment you can write something like

$\llap{\textrm{\ding{173}}}$

at the beginning of the line where you want that symbol.

MWE:

\documentclass[english,a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{changepage}
\usepackage{xcolor}
\usepackage{pifont}

\begin{document}

\clearpage
\begin{table}[ht]
\begin{adjustwidth}{-3.7cm}{}
\begin{tabular}{|p{.6\textwidth}|p{.75\textwidth}|}
\hline
{\begin{lstlisting}[mathescape=true,
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={Java},
numbersep=18pt,numbers=left,xleftmargin=1.2cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
&
{\begin{lstlisting}[mathescape=true,
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={Java},
numbersep=16pt,
numbers=left,
xleftmargin=1cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
$\llap{\textrm{\ding{173}}}$    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
$\llap{\textrm{\ding{173}}}$        x.thread.join(0);
    }
}
\end{lstlisting}}
\\
\hline
\end{tabular}
\end{adjustwidth}
\caption{\label{fig:text}text experiment ent experiment experiment}
\end{table}
\end{document} 

Output:

enter image description here

share|improve this answer
    
very cool thank you @karlkoeller! –  Hakan Apr 1 at 7:53
    
@Hakan You're welcome. –  karlkoeller Apr 1 at 8:06
    
I also look at page 79, table:261 making a filled circle with this command: '$\llap{$\FilledSmallSquare}$' but it does not work. What should I do in order to use that? –  Hakan Apr 1 at 8:12
1  
@Hakan \usepackage[geometry]{ifsym} in the preamble and then $\llap{\textrm{\FilledSmallSquare}}$ –  karlkoeller Apr 1 at 8:28
    
thank you again :) –  Hakan Apr 1 at 8:33
add comment

Another option with tikz. The technique used is similar to that of Karl, but I used escapechar key.

escapechar=|,

And the numbers are put as a node with overlay option so as to not disturb other things.

Code:

\documentclass[english,a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{changepage}
\usepackage{xcolor}
\usepackage{tikz}
\tikzset{mynode/.style={draw=blue,circle,inner sep=1pt,font=\tiny,anchor=south}
}

\begin{document}

\clearpage
\begin{table}[ht]
\begin{adjustwidth}{-3.7cm}{}
\begin{tabular}{|p{.6\textwidth}|p{.75\textwidth}|}
\hline
{\begin{lstlisting}[escapechar=|,
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={Java},
numbersep=18pt,numbers=left,xleftmargin=1.2cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
&
{\begin{lstlisting}[escapechar=|,
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={Java},
numbersep=16pt,
numbers=left,
xleftmargin=1cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
|\tikz[overlay]\node[mynode,fill=orange,yshift=-0.8ex]{1};|    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
|\tikz[overlay]\node[mynode,fill=violet,yshift=-1ex]{173};|        x.thread.join(0);
    }
}
\end{lstlisting}}
\\
\hline
\end{tabular}
\end{adjustwidth}
\caption{\label{fig:text}text experiment ent experiment experiment}
\end{table}
\end{document}

enter image description here

Along comes the benefits of tikz like filling, drawing etc to make the circle more beautiful.

share|improve this answer
    
This also cool, I will try it. Thanks! –  Hakan Apr 1 at 9:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.