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}
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. ;-)

  • Thank you, however, I need also the circle to be of the same dimension. – Guido Muscioni Apr 24 '18 at 23:29
  • @GuidoMuscioni Well, I can write something assuming that $SN$ are the largest objects you will encircle. But is that really what you want? What if you encounter even larger object later? – user121799 Apr 24 '18 at 23:31
  • I mean I would like to have all circles to have the same dimension, $SN$ is a simplification, I have also more complex symbols. @marmot – Guido Muscioni Apr 24 '18 at 23:32
  • 1
    @GuidoMuscioni Without scanning twice you will not know what your widest element would be. You need to set a maximum width to have a one shot solution – percusse Apr 24 '18 at 23:34
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

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

  • Thank you, however this solution overlaps circle with the borders. @samcarter – Guido Muscioni Apr 24 '18 at 23:41
  • @GuidoMuscioni They don't overlap, I adjusted the row height to make the circles touch the lines. You can choose another array stretch. – samcarter is at topanswers.xyz Apr 24 '18 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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