在表格中制作一个包含数字的空白圆圈

在表格中制作一个包含数字的空白圆圈

我想知道是否可以在列表或表格中的某一行旁边用未填充的圆圈突出显示一个数字,如下图所示?

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

在此处输入图片描述

答案1

您可以使用包中定义的符号pifont(参见第 77 页的表 254综合 LaTeX 符号列表)。

将该选项添加mathescape=true到你的listing环境中,你可以编写类似

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

在您想要该符号的行首。

梅威瑟:

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

输出:

在此处输入图片描述

答案2

另一个选择是tikz。所用的技术与 Karl 的类似,但我使用了escapechar键。

escapechar=|,

并且将数字作为选项放置,node以免overlay干扰其他事物。

代码:

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

在此处输入图片描述

随之而来的是填充,绘制等好处tikz,使圆圈变得更加美丽。

相关内容