0

I am trying to have 5 circles in a row filled with either darkgray or lightlightgray or half-filled (to indicate skill level on a CV). This all works fine as long as I use rotations of (multiples of) 90 degrees, but if I use other rotation in between, different things happen.
EDIT: i updated the code to make it standalone

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\newcommand{\lc}{\tikz\draw[lightgray,fill=lightgray] (0,0) circle (.8ex); }
\newcommand{\dc}{\tikz\draw[darkgray,fill=darkgray] (0,0) circle (.8ex); }

\def\AngleA{0}
\newcommand{\hc}{\begin{tikzpicture}
        \draw [lightgray, fill=lightgray] (0,0) coordinate (a) arc (\AngleA+90:\AngleA-90:.8ex) ;
        \draw [darkgray, fill=darkgray] (a) arc (\AngleA+90:\AngleA+270:.8ex) ;
    \end{tikzpicture}
}

\def\AngleB{45}
\newcommand{\hcb}{\begin{tikzpicture}
        \draw [lightgray, fill=lightgray] (0,0) coordinate (a) arc (\AngleB+90:\AngleB-90:.8ex) ;
        \draw [darkgray, fill=darkgray] (a) arc (\AngleB+90:\AngleB+270:.8ex) ;
    \end{tikzpicture}
}

\def\Rotation{45}
\newcommand{\hcc}{\begin{tikzpicture}
        \draw [lightgray, fill=lightgray, transform canvas={rotate=\Rotation}] (0,0) coordinate (a) arc (90:-90:.8ex) ;
        \draw [darkgray, fill=darkgray, transform canvas={rotate=\Rotation}] (a) arc (90:270:.8ex);
        {\rotate{45}}
    \end{tikzpicture}
}

\begin{document}

aligning circles\newline
\dc\dc\hc\lc\lc hc\newline
\dc\dc\hcb\lc\lc hcb\newline
\dc\dc\hcc\lc\lc hcc


\end{document}


 

In this case, lc, dc, and hc are my empty, full, and half-full circles. For the half-full circles, I use two arcs to make two touching semicircles. hcb and hcc my attempts at rotating the half-full circles, but neither is formatted as I intend.

For hcb, I changing the beginning and end of the arcs. Here, the bounding box of the circle rotates along with the circle so that everything else gets shifted to the right. The shift is pretty small, but enough to mess up the layout (I get the same effect if I instead specify rotate=45 behind the fill-color).

For hcc, I use transform canvas to rotate the semicircles, but it is now shifted around some point other than the center of the circle. (I have tried using transform shape instead, bit this did not result in any rotation at all).

I am not sure whether I am using the correct way top rotate these and forgetting to add some parameter or whether I should use a completely different way to rotate.

enter image description here (In the image I drew the red boxes externally to illustrate the problem, because I don't know how to do that in tex)

3
  • Welcome to TeX.SX! Please always post a full and compilable example on this site. Jan 26, 2022 at 18:10
  • 1
    thanks for the feedback @JasperHabicht. Is it ok now?
    – db_
    Jan 27, 2022 at 12:23
  • This is great! Thank you! Jan 27, 2022 at 17:00

1 Answer 1

1

Welcome to TeX.SX! I would probably use the baseline option for all the inline tikz macros to ensure correct placement and then do something like the following:

\documentclass{article}
\usepackage{tikz}

\newcommand{\lc}{\tikz[baseline=-.8ex]\draw[lightgray,fill=lightgray] (0,0) circle (.8ex); }

\newcommand{\dc}{\tikz[baseline=-.8ex]\draw[darkgray,fill=darkgray] (0,0) circle (.8ex); }

\newcommand{\hc}[1][0]{\begin{tikzpicture}[baseline=-.8ex]
        \draw[lightgray,fill=lightgray] (0,0) circle (.8ex);
        \draw[darkgray,fill=darkgray,rotate=#1] (0,0) -- (0,.8ex) arc (90:270:.8ex) -- cycle;
    \end{tikzpicture}
}

\begin{document}

\dc\hc\hc[45]\lc\lc ABC

\end{document}

enter image description here


Edit

Since your problem seems not only to be the vertical but also the horizontal alignment, I would suggest that you add the clip option to the first \draw macro for the half-filled circle. If you do this, you cannot add the color specification to the \draw macro any more, but you can add it to the \tikzpicture to set lightgray (or whatever your light gray actually is) as the default color. Also, it will help if you remove any whitespace from all three macros:

\documentclass{article}
\usepackage{tikz}

\newcommand{\lc}{\tikz[baseline=-.8ex]\draw[lightgray,fill=lightgray] (0,0) circle (.8ex);}
\newcommand{\dc}{\tikz[baseline=-.8ex]\draw[darkgray,fill=darkgray] (0,0) circle (.8ex);}

\newcommand{\hc}[1][0]{%
    \begin{tikzpicture}[baseline=-.8ex,lightgray]
            \draw[clip,fill] (0,0) circle (.8ex);
            \draw[darkgray,fill=darkgray,rotate=#1] (0,0) -- (0,.8ex) arc (90:270:.8ex) -- cycle;
    \end{tikzpicture}%
}

\begin{document}

\dc\hc\hc[45]\lc\lc ABC

\end{document}

enter image description here

You could then add spaces between the macros in the document body or more precisely position the circles in some other way.

4
  • Thanks for your reply. In this example the gap between the 2nd and 3rd circle is slightly larger than between the others (similar to my hcb function above) and so the same problem exists. It is not by much, but enough to make the layout look off
    – db_
    Jan 27, 2022 at 12:03
  • here is what it looks like if I add your code
    – db_
    Jan 27, 2022 at 12:34
  • This is quite interesting. I assume that this is due to rounding errors or bounding boxes that affect the spacing. You can use a circle path (the same you use for the fully filled circles) to clip the half-filled circle, which should result in correct spacing. See my edit. Jan 27, 2022 at 16:59
  • 1
    Perfect solution! Adding a space behind \end{tikzpicture} (and before the`%) gets the spacing back as it was.
    – db_
    Jan 27, 2022 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .