3

I need to have a sequence of lines, in which some symbols are circled. Right now I am using a table, the output is shown in the picture:

enter image description here

However as you can see the circles are overlapping with the border of the table, moreover the circles on SN are bigger than the one for S[0-9]. I would like to have an equal distance from the border and an equal circle size for every symbol. These should also include having the same dimension for each row. The code I am using is for the circle the following:

\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

The code for the table:

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

I have taken the code from a previous question: How do I draw a circle around a term in an align* equation?

Thank you.

MWE:

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

3 Answers3

4

Here is a proposal. Note that you need to reorder table and center.

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

enter image description here

UPDATE: Because you asked me to do that. @samcarter was faster anyway, but personally I'd not go that way.

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

And thanks @percusse, you're right, as always. ;-)

4

You can simply use the rules from booktabs which have some vertical padding around them:

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

enter image description here

Bernard
  • 271,350
3

To make the circles the same size, you can specify a 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}

enter image description here