I am teaching a course in history of mathematics and would like to draw something like the following:

enter image description here

The bullet points should be possible to draw on the lines and in between. Can anyone help me? Thank you very much!

  • 5
    Welcome to TeX.SE! Can you please add the code you have tried so far? – Kurt Apr 25 at 7:47
  • 2
    You will find a tutorial for such shapes at the beginning of TikZ manual (the one dedicated to drawing algorithm). It is very well explained. All you have to do is to turn the white circles of its example into black. – sztruks Apr 25 at 7:49
  • Are the grid sizes fixed as in your MWE (4 horizontal lines and 2 vertical), or are they also variable? – Andrew Apr 25 at 8:27
  • Just a random thought: You can tweak qcircuit – pushpen.paul Apr 25 at 17:33

As you intend to draw "quite a few" of these you'll need a reasonable interface, so how about using code like this


to produce something like this:

enter image description here

The way that this works is that the \abacus command accepts a comma separated list of "abacus rows", which start from the bottom of the abacus and climb upwards. Each "abacus row" is itself a comma separated list that gives the number of balls in each column of the abacus, from left to right.

Here's the full code:


  pics/abacus/.style = {
        \ifnum#1>0% have to treat 0 separately
          \foreach \ball [evaluate=\ball as \x
            using {(\ball-0.5-#1/2)*0.2}] in {1,...,#1} {
            \fill[black] (\x,0) circle (2.5pt);
  /tikz/abacus/.is family,% default values
    xscale/.initial=1,  % default xscale=1 (no scaling)
    yscale/.initial=0.6,% default yscale=0.6
    columns/.initial=2, % default of 2 vertical rules
    rows/.initial=4     % default of 4 horizontal rules
% shortcut for accessing options

\newcommand\abacus[2][]{\tikzset{abacus, #1}%
     \foreach \ypos in {1,...,\AbacusOption{rows}} {
     \foreach \xpos in {1,...,\AbacusOption{columns}} {
         \draw(2*\xpos, 0)--++(0,2*\AbacusOption{rows});
     \foreach \row [count=\ypos] in {#2} {
         \foreach \col [count=\xpos] in \row {
             \draw (2*\xpos-1,\ypos) pic{abacus={\col}};




The \abacus command accepts an optional argument that accepts a comma separated list of key-value pairs for changing the default number of rows and columns and the x and y scaling. For example,

\abacus[rows=2, columns=3, xscale=0.5, yscale=0.3]{{1,2,3,4},{0,3,1}}


enter image description here


Here I draw the first picture. You can draw the other based on this.

\foreach \i in {1,2} \draw (\i,-.2) -- (\i,3.2);
\foreach \i in {0,1,2,3} \draw (0,\i) -- (3,\i);
\foreach \x/\y in {
} \fill (\x,\y) circle (2pt);

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.