表格中圆圈内的符号

表格中圆圈内的符号

我需要一系列的行,其中的一些符号被圈起来。现在我正在使用一个表格,输出如图所示:

在此处输入图片描述

但是,正如您所看到的,圆圈与表格的边框重叠,而且 SN 上的圆圈比 S[0-9] 上的圆圈大。我希望每个符号与边框的距离相等,圆圈大小也相等。这些还应包括每行具有相同的尺寸。我使用的圆圈代码如下:

\usepackage{mathtools}% superior to amsmath
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base)] \node[draw,circle,inner sep=1pt] (math) {$\m@th#1#2$};%
}
\makeatother

该表的代码:

\begin{center}
        \begin{table}[]
            \centering
            \label{my-label}
            \begin{tabular}{ccccc}
                \hline
                S1  & S1  & $\mathcircled{S1}$  & ... & S1  \\ \hline
                $\mathcircled{S2}$  & $\mathcircled{S2}$  & S2  & ... & S2  \\ \hline
                ... & ... & ... & ... & ... \\ \hline
                SN  & $\mathcircled{SN}$  & $\mathcircled{SN}$  & ... & SN  \\ \hline
            \end{tabular}
        \end{table}
    \end{center}

我从上一个问题中获取了代码:如何在 align* 方程式中的某个项周围画一个圆圈?

谢谢。

梅威瑟:

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{multirow}
\usepackage{mathtools}% superior to amsmath
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base)] \node[draw,circle,inner sep=1pt] (math) {$\m@th#1#2$};%
}
\makeatother
\usepackage{tikz-cd}
\newtheorem{definition}{Definition}[section]    %% this does it

\newcommand{\cmmnt}[1]{\ignorespaces}


\begin{document}

    \newpage


    \begin{center}
        \begin{table}[]
            \centering
            \label{my-label}
            \begin{tabular}{ccccc}
                \hline
                S1  & S1  & $\mathcircled{S1}$  & ... & S1  \\ \hline
                $\mathcircled{S2}$  & $\mathcircled{S2}$  & S2  & ... & S2  \\ \hline
                ... & ... & ... & ... & ... \\ \hline
                SN  & $\mathcircled{SN}$  & $\mathcircled{SN}$  & ... & SN  \\ \hline
            \end{tabular}
        \end{table}
    \end{center}

答案1

这是建议。请注意,您需要重新排序tablecenter

\documentclass{report}
\usepackage{mathtools}% superior to amsmath
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base),outer sep=auto]{\node[draw,circle,inner
    sep=1pt]
    (math) {$#1#2$};
    \path (math.north)--++(0,1pt);
    \path (math.south)--++(0,-1pt);}%
}
\makeatother
\begin{document}
\begin{table}[ht]
            \centering

            \begin{tabular}{ccccc}
                \hline
                S1  & S1  & $\mathcircled{S1}$  & ... & S1  \\ \hline
                $\mathcircled{S2}$  & $\mathcircled{S2}$  & S2  & ... & S2  \\ \hline
                ... & ... & ... & ... & ... \\ \hline
                SN  & $\mathcircled{SN}$  & $\mathcircled{SN}$  & ... & SN  \\ \hline
            \end{tabular}
\caption{A table with circles.}\label{my-label}
\end{table}

\end{document}

在此处输入图片描述

更新:因为你要求我这么做。@samcarter 无论如何都更快,但我个人不会这么做。

\documentclass{report}
\usepackage{mathtools}% superior to amsmath
\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base),outer sep=auto]{\node[draw,circle,inner
    sep=1pt,minimum width=0.8cm]
    (math) {$#1#2$};
    \path (math.north)--++(0,1pt);
    \path (math.south)--++(0,-1pt);}%
}
\makeatother
\begin{document}
\begin{table}[ht]
            \centering

            \begin{tabular}{ccccc}
                \hline
                S1  & S1  & $\mathcircled{S1}$  & ... & S1  \\ \hline
                $\mathcircled{S2}$  & $\mathcircled{S2}$  & S2  & ... & S2  \\ \hline
                ... & ... & ... & ... & ... \\ \hline
                SN  & $\mathcircled{SN}$  & $\mathcircled{SN}$  & ... & SN  \\ \hline
            \end{tabular}
\caption{A table with circles.}\label{my-label}
\end{table}

\end{document}

谢谢@percusse,一如既往,你是对的。;-)

答案2

booktabs您可以简单地使用在其周围有一些垂直填充的规则:

\documentclass[12pt]{article}

\usepackage{tikz}

\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base)] \node[draw,circle,inner sep=1pt] (math) {$\m@th#1#2$};%
}
\makeatother

\usepackage{booktabs}

\begin{document}

        \begin{table}[]
            \centering
            \label{my-label}
            \begin{tabular}{ccccc}
                \toprule
                S1 & S1 & $\mathcircled{S1}$ & ... & S1 \\ \midrule
                $\mathcircled{S2}$ & $\mathcircled{S2}$ & S2 & ... & S2 \\ \midrule
                ... & ... & ... & ... & ... \\ \midrule
                SN & $\mathcircled{SN}$ & $\mathcircled{SN}$ & ... & SN \\ \bottomrule
            \end{tabular}
        \end{table}

    \end{document} 

在此处输入图片描述

答案3

要使圆的大小相同,可以指定minimum size

\documentclass[12pt]{article}

\usepackage{tikz}
\makeatletter
\newcommand\mathcircled[1]{%
    \mathpalette\@mathcircled{#1}%
}
\newcommand\@mathcircled[2]{%
    \tikz[baseline=(math.base)] \node[draw,circle,minimum size=30pt] (math) {$\m@th#1#2$};%
}
\makeatother

\usepackage{booktabs}


\begin{document}


\begin{table}[htbp]
    \centering
    \renewcommand{\arraystretch}{1.8}
    \belowrulesep=1ex
    \aboverulesep=1ex
    \begin{tabular}{ccccc}
        \midrule
        S1  & S1  & $\mathcircled{S1}$  & $\dots$ & S1  \\ \midrule
        $\mathcircled{S2}$  & $\mathcircled{S2}$  & S2  & $\dots$ & S2  \\ \midrule
        $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ \\ \midrule
        SN  & $\mathcircled{SN}$  & $\mathcircled{SN}$  & $\dots$ & SN  \\ \midrule
    \end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容