10

I used this answer to create solid circle in a table. I am creating a table that will use a traffic light system to monitor progress. While I am able to product solid circles would it be possible to produce half and half circles. The aim is to have both red orange and green circles and a combination of half and half circles of red/orange and orange/green to give a more nuances view of progress.

MWE

\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{lipsum} % just for dummy text

\begin{document}

\begin{table}[H]
\setlength\extrarowheight{2mm}
    \centering
    \begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
        \hline
        \textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \tikz\draw[green,fill=green] (0,0) circle (1.0ex); & What is end product   \\ \hline          
Aim 2 & what needs to be done & who & when & \tikz\draw[orange,fill=orange] (0,0) circle (1.0ex); & What is end product   \\ \hline
Aim 3 & what needs to be done & who & when & \tikz\draw[red,fill=red] (0,0) circle (1.0ex); & What is end product  \\ \hline
 \end{tabularx}
\end{table}

\end{document}
13

Something like this?

enter image description here

\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{tikz,float}
\usepackage{tabularx}
\usepackage{xparse}

\NewDocumentCommand{\statcirc}{ O{#2} m }{%
    \begin{tikzpicture}
    \fill[#2] (0,0) circle (1.0ex); % Fill circle with base colour (arg#2)
    \fill[#1] (0,0) -- (180:1ex) arc (180:0:1ex) -- cycle; % Fill a half circle filled with second colour (arg#1), if specified
    \end{tikzpicture}
}

\begin{document}

\begin{table}[H]
\setlength\extrarowheight{2mm}
    \centering
    \begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
        \hline
        \textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \statcirc{green} & What is end product   \\ \hline          
Aim 2 & what needs to be done & who & when & \statcirc[orange]{green} & What is end product   \\ \hline
Aim 3 & what needs to be done & who & when & \statcirc[red]{orange} & What is end product  \\ \hline
 \end{tabularx}
\end{table}

\end{document}

If you want to have a half circle, provide the second colour as an optional argument. This second colour will appear at the top.

\statcircle[top colour]{bottom colour}

A little note on the TikZ code:

\fill[#1] (0,0) -- (180:1ex) arc (180:0:1ex) -- cycle;
  • \fill[#1]: create a fill shape with the colour specified
  • (0,0) -- (180:1ex): 'draw' the shape path from (0,0) to the point specified in polar coordinates, 180 degrees (measured clockwise from positive x-axis) and radius 1ex.
  • arc (180:0:1ex): continue 'drawing' the shape path as a circular arc, with fixed radius 1ex, starting angle 180 degrees, end angle 0 degrees. this creates the half circle.
  • -- cycle;: complete the loop back to origin

With that in mind, if you want a circle split vertically, you just need to change the starting and end angle during the drawing of the arc. As an example:

\fill[#1] (0,0) -- (90:1ex) arc (90:270:1ex) -- cycle; gives you:

vert

\fill[#1] (0,0) -- (45:1ex) arc (45:215:1ex) -- cycle; gives you:

diag

  • Just out of curiosity if I wanted the circles to be split vertically or diagonally how would I adjust for that. Is it the code in relation to the arc? – gman May 7 '17 at 13:46
  • 1
    \fill[#1] (0,0) -- (90:1ex) arc (90:270:1ex) -- cycle; for example. I'll make an extra comment in my answer in a bit – Troy May 7 '17 at 13:48
12

One more (and simple) example with use of shapes.geometry packages :-)

enter image description here

\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\newcommand{\semaphore}[2]{
\tikz[node distance=3mm,baseline]
    {
    \node (s1) [semicircle, fill=#1, minimum size=3mm] {};
    \node (s1) [semicircle, fill=#2, minimum size=3mm, rotate=180, below=of s1] {};
    }
                }
\usepackage{tabularx}
\usepackage{ragged2e} % added for better adjust of cells' content
\newcolumntype{L}{>{\RaggedRight}X} % for cells with left aligned content
\usepackage{lipsum} % just for dummy text

\begin{document}
    \begin{table}
\setlength\extrarowheight{2mm}
    \centering
    \begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
        \hline
        \textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
Aim 1 & what needs to be done & who & when & \semaphore{green}{green}   & What is end product   \\ \hline
Aim 2 & what needs to be done & who & when & \semaphore{orange}{green}  & What is end product   \\ \hline
Aim 3 & what needs to be done & who & when & \semaphore{red}{orange}    & What is end product  \\ \hline
 \end{tabularx}
    \end{table}
\end{document}

Addendum: For half circle rotated for arbitrary angle:

enter image description here

\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\newcommand{\semaphore}[3]{% #1: color of circle, 
                           % #2: color of semicircle
                           % #3: angle of semicircle 
\tikz[node distance=0mm,baseline]
    {
    \node (s1) [circle, fill=#1, minimum size=6mm] {};
    \node      [semicircle, fill=#2, 
                inner sep=0pt, outer sep=0pt, minimum size=3mm,
                anchor=south,
                at={(s1.center)}, rotate=#3] {};
     }
                        }% end of command
\usepackage{makecell, tabularx}
\usepackage{ragged2e} % added for better adjust of cells' content
\newcolumntype{L}{>{\RaggedRight}X} % for cells with left aligned content
\usepackage{lipsum} % just for dummy text
\usepackage{graphicx}

\begin{document}
    \begin{table}
\setlength\extrarowheight{2mm}
    \centering
    \begin{tabularx}{\textwidth}{| L | L | l | l | c | L |}
        \hline
        \textbf{Strategy} & \textbf{Action} & \textbf{Owner} & \textbf{Due} & \textbf{Status} & \textbf{Outcome} \\ \hline
Aim 1 & what needs to be done & who & when & \semaphore{green}{green}{0}    & What is end product   \\ \hline
Aim 2 & what needs to be done & who & when & \semaphore{orange}{green}{90}  & What is end product   \\ \hline
Aim 3 & what needs to be done & who & when & \semaphore{red}{orange}{45}    & What is end product   \\ \hline
Aim 4 & what needs to be done & who & when & \semaphore{green}{red}{0}      & What is end product   \\ \hline
Aim 5 & what needs to be done & who & when & \semaphore{green}{red}{30}     & What is end product   \\ \hline
 \end{tabularx}
    \end{table}
\end{document}
  • Would it be possible with this solution for the circles to be also split vertically or diagonally if wanted? – gman May 7 '17 at 13:50
  • @gman, yes, with appropriate rotated sempahore. However, this require redesign its definition or use of rotatebox from graphicx package. After while I will add this possibilities to my answer. – Zarko May 7 '17 at 13:55
  • @gman, I finally have some spar time and extend first solution with addendum with solution where you can define arbitrary angle of semicircle(s). – Zarko May 7 '17 at 17:23
8

Something like this?

result

I have taken the liberty of adding the booktabs package and removing the table lines (they are generally discouraged, see the booktabs package). You can of course add them back if you truly want them; it is in the end primarily a matter of taste.

If you want to peruse the booktabs docs, they can be found here: http://ctan.org/pkg/booktabs

I have made a few new commands which create the circles for added convenience. You could of course also create a single command and pass the desired color(s) to it as argument(s). Your mileage and preference may vary.

\documentclass[12pt,a4paper]{memoir}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{tabularx}

\newcommand*\greencirc{\tikz\fill[fill=green] (0,0) circle (1.0ex);}
\newcommand*\orangecirc{\tikz\fill[fill=orange] (0,0) circle (1.0ex);}
\newcommand*\redcirc{\tikz\fill[fill=red] (0,0) circle (1.0ex);}
\newcommand*\redorangecirc{%
    \begin{tikzpicture}
        \fill[red] (0,0) circle (1ex);
        \clip (-1ex,-1ex) rectangle (1ex,0);
        \fill[orange] (0,0) circle (1ex);
    \end{tikzpicture}}
\newcommand*\orangegreencirc{%
    \begin{tikzpicture}
        \fill[orange] (0,0) circle (1ex);
        \clip (-1ex,-1ex) rectangle (1ex,0);
        \fill[green] (0,0) circle (1ex);
    \end{tikzpicture}}

\begin{document}

\begin{table}
\setlength\extrarowheight{2mm}
    \centering
    \begin{tabularx}{\textwidth}{XXllcX}
        \toprule
        \textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\
        \midrule
        Aim 1 & what needs to be done & who & when & \greencirc & What is end product   \\
        Aim 2 & what needs to be done & who & when & \orangecirc & What is end product   \\
        Aim 3 & what needs to be done & who & when & \redcirc & What is end product  \\
        Aim 4 & what needs to be done & who & when & \redorangecirc & What is end product  \\
        Aim 5 & what needs to be done & who & when & \orangegreencirc & What is end product  \\
        \bottomrule
 \end{tabularx}
\end{table}

\end{document}

As a side note: There is no need to load the xcolor package; tikz loads that itself.

8

We, at work, also use the quarter semaphores.

It's easy to do with tkz-euclide package.

I have created a pic with three args: background color, grade (90/180/270) of the angle of the sector which has to be colored in another way, another color. If the angle is = 0 (that is, there is only one color) the third argument is ignored.

\documentclass[12pt,a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{tkz-euclide}
\usetkzobj{all} 
\tikzset{%
    pics/sema/.style args={#1/#2/#3}{code={%
        \ifstrequal{#2}{0}{%
            \node[circle,minimum width=2mm,draw,fill=#1] {};
        }{%
            \tkzDefPoint(0,0){O}
            \tkzDrawSector[R,fill=#1](O,2mm)(90,90-#2)
            \tkzDrawSector[R,fill=#3](O,2mm)(90-#2,90-360)
    }
    }},
}
\usepackage{float}
\usepackage{tabularx}
\usepackage{lipsum} % just for dummy text


\begin{document}

    \begin{table}[H]
        \setlength\extrarowheight{2mm}
        \centering
        \begin{tabularx}{\textwidth}{| X | X | l | l | c | X |}
            \hline
            \textbf{{Strategy}} & \textbf{{Action}} & \textbf{{Owner}} & \textbf{{Due}} & \textbf{{Status}} & \textbf{{Outcome}} \\ \hline
            Aim 1 & what needs to be done & who & when & \tikz\pic{sema=yellow/0/}; & What is end product   \\ \hline          
            Aim 2 & what needs to be done & who & when & \tikz\pic{sema=yellow/90/green}; & What is end product   \\ \hline
            Aim 3 & what needs to be done & who & when & \tikz\pic{sema=yellow/180/green}; & What is end product  \\ \hline
            Aim 4 & what needs to be done & who & when & \tikz\pic{sema=yellow/270/green}; & What is end product  \\ \hline
            Aim 5 & what needs to be done & who & when & \tikz\pic{sema=red/0/}; & What is end product  \\ \hline
            Aim 6 & what needs to be done & who & when & \tikz\pic{sema=red/90/yellow}; & What is end product  \\ \hline
            Aim 7 & what needs to be done & who & when & \tikz\pic{sema=red/180/yellow}; & What is end product  \\ \hline
        \end{tabularx}
    \end{table}

\end{document}

enter image description here

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.