# Making a chart-like graph in latex (for Number Theory)

I had been taking my Number theory class notes in latex and all is done except one last bit (which I have been postponing for ages now!).

I am trying to find the best way of transferring the following graph/chart into latex but was not sure which package should I choose.

I would really appreciate some guidance and suggestions.

P.S. I worked/have been working in Overleaf. Since the whole document is too long to be posted in this question, here is the link to it, in case it may be useful. (Let me know if it wouldn't work.)

P.S.S. I have previously worked with tikz mostly (for Graph Theory and Game Theory stuff) and some other packages which were mostly used to generate functional graphs; so, based on this experience, I was thinking this graph might be constructed with tikz as well.

• It would be great if you could show us what you have tried. Posting a minimal working example that indicates what you are trying to do makes it easier for people to understand what you want. It also makes it easier for people to help you, since they have some code to start from, and hence much more likely that some one will try to help you. Please don't post your entire document. A MWE should be as small as possible to illustrate your problem.
– user30471
Commented Aug 31, 2020 at 2:08
• @ElenKhachatryan please have a look at the solution with tkz-euclide given below if it meets your requirement Commented Sep 1, 2020 at 1:31

In Tikz, you can use grid to draw the grid and then define a node that draws a filled small circle (in the code below plupp). After that it is mostly a matter of positioning text nodes.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[plupp/.style={circle,draw,inner sep=1pt,fill=black}]
\draw (0,0) grid (7,5);
\node[anchor=north east] at (0,0){$0$};
\node[anchor=south east] at (0,5){$\alpha$};
\node[anchor=south west] at (7,5){$N$};
\node[anchor=north west] at (7,0){$R$};
\draw (0,0) -- (7,5);
\node[plupp,label={180:$C$}] at (0,2){};
\node[plupp,label={-90:$A$}] at (3,0){};
\node[plupp,label=110:$P$] at (7*2/5,2){};
\node[plupp,label=90:$\mu$] at (3,5*3/7){};
\node[plupp,label=-45:$B$] at (3,2){};
\draw[<->](0,-0.7) -- +(3,0) node[pos=0.5,fill=white]{$\tfrac{p-1}{2}$};
\draw[<->](0,-1.3) -- +(7,0) node[pos=0.5,fill=white]{$p$};
\draw[<->](-0.7,0) -- +(0,2) node[pos=0.5,fill=white]{$\tfrac{g-1}{2}$};
\draw[<->](7.5,0) -- +(0,5) node[pos=0.5,fill=white]{$g$};
\end{tikzpicture}
\end{document}


• Thank you so much @StefanH ! Do you mind if I include you in my list of helpful contributors (so far it would be only you on the list (LOL) until a couple of people proofread everything), and if so, what name would you like me to use? (It is nothing official, and simply for my note-taking archive completion purposes. As of now, not intending to sell or profit from it :D.) Commented Sep 7, 2020 at 2:22
• Just glad I could help. It is a very minor typographic contribution so you don't need to mention it. Commented Sep 7, 2020 at 15:04

Well, here is a starter using the tikz package

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

\begin{document}

\begin{tikzpicture}
\draw[gray, thick] (0,0) -- (0,6);
\draw[gray, thick] (1,0) -- (1,6);
\draw[gray, thick] (2,0) -- (2,6);
\draw[gray, thick] (3,0) -- (3,6);
\draw[gray, thick] (4,0) -- (4,6);
\draw[gray, thick] (5,0) -- (5,6);
\draw[gray, thick] (6,0) -- (6,6);
\draw[gray, thick] (7,0) -- (7,6);

\draw[gray, thick] (0,0) -- (7,0);
\draw[gray, thick] (0,1) -- (7,1);
\draw[gray, thick] (0,2) -- (7,2);
\draw[gray, thick] (0,3) -- (7,3);
\draw[gray, thick] (0,4) -- (7,4);
\draw[gray, thick] (0,5) -- (7,5);
\draw[gray, thick] (0,6) -- (7,6);
\draw[black, thick] (0,0) -- (7,6);

\filldraw[black] (0,0) circle (2pt) node[anchor=east] {0};
\filldraw[black] (0,2) circle (2pt) node[anchor=east] {C};
\filldraw[black] (7,0) circle (2pt) node[anchor=west] {R};
\filldraw[black] (0,6) circle (2pt) node[anchor=east] {2};
\filldraw[black] (7,6) circle (2pt) node[anchor=west] {N};

\end{tikzpicture}

\end{document}


I am not sure about the intermediate points. If it were me I might have created it as a PowerPoint figure and export as pdf. To learn more about the tikz package, refer to this documentation:

https://www.overleaf.com/learn/latex/TikZ_package

I am pretty sure you can create the arrows and equation annotations using similar commands, as long as you know their desired positions on the page.

• Would foreach shorten this answer quite a bit?
– Simd
Commented Aug 31, 2020 at 6:35
• You should use grid instead of drawing the lines one by one, as in this answer. Commented Aug 31, 2020 at 12:27

Consider asymptote as an option.

// tab-numt.asy
//
// run
//    asy tab-numt.asy
//
// to get a standalone pdf picture
//    tab-numt.pdf
//
settings.tex="pdflatex";
size(9cm);
pen linePen=darkblue+0.7bp, grayPen=gray(0.3)+0.7bp;
int n=3, m=2, p=2*n+1, q=2*m+1;

guide hLine[], vLine[];
for(int i=0;i<=q;++i)hLine[i]=(0,i)--(p,i);
for(int i=0;i<=p;++i)vLine[i]=(i,0)--(i,q);

pair N=(p,q), O=(0,0), Q=(0,q), R=(p,0),
A=((p-1)/2,0), C=(0,(q-1)/2), B=(A.x,C.y),
M=intersectionpoint(O--N,vLine[(p-1)#2]),
P=intersectionpoint(O--N,hLine[(q-1)#2]),
Z=(B+P+M)/3
;
pair[] pos={N,O,Q,R,A,B,C,P,M}; string name="NOQRABCPM";

draw(hLine,linePen); draw(vLine,linePen);
draw(O--N,linePen);

pair dx=(0.62,0), dy=(0,0.5);

draw((O-dy)--(A-dy),grayPen,arr); label("$\frac{p-1}2$",(O+A)/2-dy,UnFill);

draw((O-2dy)--(R-2dy),grayPen,arr); label("$p$",(O+R)/2-2dy,UnFill);

draw((O-dx)--(C-dx),grayPen,arr); label("$\frac{q-1}2$",(O+C)/2-dx,UnFill);

draw((N+dx)--(R+dx),grayPen,arr); label("$q$",(N+R)/2+dx,UnFill);

dot(pos[4:9],UnFill);

for(int i=0;i<7;++i) label("$"+substr(name,i,1)+"$",pos[i],unit(pos[i]-Z));
label("$M$",M,plain.NW); label("$P$",P,plain.S);


a tkz-euclide solution

\documentclass[12pt]{article}

% \usepackage{amsmath}
\usepackage{tkz-euclide}

\begin{document}
\begin{tikzpicture}
%the grid
\tkzInit[xmin=0,xmax=7,ymin=0,ymax=5]
\tkzGrid
%the axes
%               \tkzDrawX[label={}]
%               \tkzDrawY[label={}]

%draw the points O, R, 2, N, A, C
\tkzDefPoints{0/0/O,7/0/R,0/5/2,7/5/N,3/0/A,0/2/C}
\tkzDrawPoints(O,R,2,N,A,C)
\tkzLabelPoints(O,R,N,A)
\tkzLabelPoints[left](2)
\tkzLabelPoints[left,yshift=6pt](C)

%segment ON
\tkzDrawSegment[](O,N)

%calculate intersections for point P, M, B
\tkzDefShiftPoint[C](0:7){Xc}
\tkzDefLine(C,Xc)
%               \tkzDrawLine(C,Xc)%
\tkzDefShiftPoint[A](90:5){Xa}
\tkzDefLine(A,Xa)
%               \tkzDrawLine(A,Xa)
\tkzInterLL(A,Xa)(C,Xc)\tkzGetPoint{B}
\tkzDrawPoint[red](B)
\tkzLabelPoints[,font=\tiny](B)

\tkzInterLL(O,N)(C,Xc)\tkzGetPoint{P}
\tkzDrawPoint[green](P)
\tkzLabelPoints[above left,font=\tiny](P)

\tkzInterLL(O,N)(A,Xa)\tkzGetPoint{M}
\tkzDrawPoint[blue](M)
\tkzLabelPoints[above,font=\tiny, xshift=-4pt](M)

%some labels
\tkzDrawSegment[dim={$g$,-20pt,above=0pt,font=\tiny}](R,N)
\tkzDrawSegment[dim={$P$,-30pt,above=-3pt,font=\tiny}](O,R)
\tkzDrawSegment[dim={$(P-1)/2$,-15pt,above=-3pt,font=\tiny}](O,A)
\tkzDrawSegment[dim={$(g-1)/2$,15pt,above=0pt,font=\tiny}](O,C)
\end{tikzpicture}

\end{document}