1

From a previous question I already have a solution to put a circle in a matrix field.

\documentclass[leqno,8pt,fleqn,table]{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings}

\def\r{0.1}

\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        minimum height=1.5em,
        text depth=0.5em,
        text height=1em,
                text centered,
        nodes in empty cells,
%%
                                row 1/.style={
            nodes={
                fill=black,
                text=white,
                %font=\bfseries
            }
        },
                rows/.style={nodes={fill=gray!10}},
                columns/.style={nodes={text width = 10em}},
                %myrowstyle/.style={
                    %row #1/.style={nodes={fill=gray!10}}
        %},
    }
}

\begin{document}
\begin{frame}
\begin{center}
\begin{tiny}
    \begin{tikzpicture}
    \matrix[table, rows={2,...,3}{fill=grey!10}, columns={1,...,5}{text width = 10em}, ampersand replacement=\&] (first)
    { 
        card \# \& date \& 1 \& 2 \& 3 \\
        ghul \& 01.01.2016 \&  \&  \&  \\
};

\fill[left color=green,right color=red] (first-2-3) circle (\r);
\fill[red] (first-2-4) circle (\r);
\fill[red] (first-2-5) circle (\r);

\end{tikzpicture}
\end{tiny}
%\vspace{4mm}
\end{center}
\end{frame}
\end{document}

However if I have additional Text inside the Field, the circle will be just on-top of the Text "covering" it. How is it possible to position the circle for example directly infront of the text e.g.: "o - Blablablablabla" where "o" stands for circle.

  • 1
    Off-topic: don't do \def\r like that! Eeeekkk!! – cfr Apr 23 '18 at 0:50
  • 1
    \fill[red] (first-2-4.west) circle (\r);? If you use \tiny on a slide, nobody is going to be able to read anything anyway, so it won't matter where your circles are. – cfr Apr 23 '18 at 0:51
  • THX. Why don't use \def\r ? – Diger Apr 23 '18 at 11:02
  • Because you haven't checked that \r isn't already defined. If it is, you are overwriting this globally. In the case of a single letter macro name, this is extremely likely. – cfr Apr 24 '18 at 22:40
2

First of all, I think @cfr has made two very good points (but I did not want to just remove your \def\r either). Then, of course you can place the circles wherever you want. Yet I must say that even though I tend to (ab)use TikZ for pretty much everything, it should be mentioned that in the case of a single-color circle the good old \textbullet does a great job. Please have a look.

\documentclass[leqno,8pt,fleqn,table]{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings}

\def\r{0.1}

\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        minimum height=1.5em,
        text depth=0.5em,
        text height=1em,
                text centered,
        nodes in empty cells,
%%
                                row 1/.style={
            nodes={
                fill=black,
                text=white,
                %font=\bfseries
            }
        },
                rows/.style={nodes={fill=gray!10}},
                columns/.style={nodes={text width = 10em}},
                %myrowstyle/.style={
                    %row #1/.style={nodes={fill=gray!10}}
        %},
    }
}

\begin{document}
\begin{frame}
\begin{center}
\begin{tiny}
    \begin{tikzpicture}
    \matrix[table, rows={2,...,3}{fill=grey!10}, columns={1,...,5}{text width = 10em}, ampersand replacement=\&] (first)
    { 
        card \# \& date \& 1 \& 2 \& 3 \\
        ghul \& 01.01.2016 \& xyz \&
        \raisebox{-2pt}{\textcolor{red}{\huge\textbullet}}~abc \&  \\
};

\fill[left color=green,right color=red] ([xshift=3mm]first-2-3.west) circle (\r);
%\fill[red] (first-2-4) circle (\r);
\fill[red] (first-2-5) circle (\r);

\end{tikzpicture}
\end{tiny}
%\vspace{4mm}
\end{center}
\end{frame}
\end{document}

enter image description here

And I am also wondering about the text size. Is is because you don't want to scare people with the "ghul"? More seriously, things tend to get received better when they are readable. You make so much effort by having the ball being two-colored, but then you just give it away by using a tiny font. Consider changing that.

  • Thanks too. I guess for the size of the textbullet you just tried as long until it matched the size 0.1 of the tikz circle, right? I mean there are not "many" possibilities, or? \tiny \small \medium \large \huge??? Is it by chance that it fits the 0.1 tikz size or is it also possible to assign a textbullet size in terms of numbers? I used tiny because I actually just prefered small fonts but I will consider changing it. – Diger Apr 23 '18 at 11:12
  • What specifically is the ~ for when writing abc? – Diger Apr 23 '18 at 11:29
  • @Diger 1. You can have any size by using \resizebox. 2. ~ represents an unbreakable space. It is not necessary here, but does not hurt either. – user121799 Apr 23 '18 at 13:28
  • Can you maybe add a quick example in how to use resizebox here? – Diger Apr 24 '18 at 9:21
  • @Diger \scalebox is even simpler. Try \raisebox{-1pt}{\textcolor{red}{\scalebox{2.5}{\textbullet}}} instead of \raisebox{-2pt}{\textcolor{red}{\huge\textbullet}}. – user121799 Apr 24 '18 at 13:29

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.