# How can I recreate this rectangle with lines, points, and labels in LaTeX?

I'm just typing this up for class and I'd appreciate some guidance like what packages I'd need and how to start?

• What does it represent? Why did you choose the biblatex tag? Aug 29 '20 at 5:48
• I tried to just tag "LaTex" it's for my linear algebra HW and it's a temperature graph. Aug 29 '20 at 5:51
• What does HW mean? I've never seen such temperature graphs, what's the point? Do you have an internet link that talks about it? Aug 29 '20 at 6:53
• Therefore, the simple reproduction of this graphic is suitable for you. Aug 29 '20 at 7:35
• I request changing the title of the question and add some details so that if someone is looking to draw something on similar lines they can find this question. Else, it might be useless for anyone else. Maybe "LaTeX basic drawing: small rectangular mesh/grid with lines, points, and labels". Aug 29 '20 at 8:43

There are a lot of packages that allow you to do this: like metapost, pstricks, asymptote, TikZ and certainly others that I forgot.

Here is a version with TikZ. If you have any questions about the code, I'm listening.

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\fill[gray!20] (0,0)rectangle(3,3);
\draw (0,0)grid(3,3);
\node foreach \j in {1,2} [left] at  (0,\j) {$10^\circ$};
\node foreach \j in {1,2} [right] at  (3,\j) {$40^\circ$};
\node foreach \i in {1,2} [below] at  (\i,0) {$30^\circ$};
\node foreach \i in {1,2} [above] at  (\i,3) {$20^\circ$};
\node foreach \i in {1,2} [above right] at  (\i,2) {$\i$};
\node foreach \lab [count=\n] in {4,3} [above right] at  (\n,1) {$\lab$};
\foreach \list[count=\j from 0] in {{1,2},{0,1,2,3},{0,1,2,3},{1,2}}
\foreach \x in \list {
\fill (\x,\j)[cyan] circle (2pt);
}
\end{tikzpicture}

\end{document}


LaTeX basic drawing using TikZ: rectangle with lines, points, and labels.

You only need one package:

\usepackage{tikz}


Let us define a blue color and a gray color for our figure:

\definecolor{mBlue}{HTML}{1F77B4}
\definecolor{mGray}{HTML}{d7dbdd}


Now create a style for the points. We do not want to write a lot of commands and options again and again. We will call this style vertex and use the command \tikzstyle{vertex}. From the options we can see that it is a circle, it is drawn with the color mBlue we defined above, and it is also filled with the same color. The separation options indirectly control how big the circle is going to be and the separation between any text you decide to write inside the node. You can also use minimimum size=0.2.

\tikzstyle{vertex}=[circle,draw=mBlue,fill=mBlue,inner sep=0.6mm, outer sep=0mm]


We can place the above three lines in the preamble, i.e., the "stuff" before \begin{document}.

We are now ready to use the figure environment and draw. Our drawings will be placed inside the tikzpicture environment. You will notice that there is also a scale option. This can be used to increase/decrease size of the figure. Interestingly, scaling does not affect the text placed inside the figure.

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=1]
% our drawing goes here
\end{tikzpicture}
\caption{The figure.}
\end{figure}


Now, the most important thing you will have to do is assign some coordinates to important points in your figure. This can seem intimidating to some in the beginning but it is easier than it seems. Let's say we denote the bottom left corner as point (0,0) and the top most point as (3,3). You can use the command \coordinate (name) at (<x>,<y>); for each of the sixteen points in the figure. However, I wanted to introduce for loops because a lot of new users miss this super convenient feature. I have added a coordinate figure.

\foreach \x in {0,...,3} {
\foreach \y in {0,...,3} {
\coordinate (\x_\y) at (\x,\y);
}
}


Now draw the outer rectangle and lines. You can fill the rectangle by using draw[fill=mGray].

\draw (0_0) -- (3_0) -- (3_3) -- (0_3) -- (0_0);
\draw (1_0) -- (1_3);
\draw (2_0) -- (2_3);
\draw (0_1) -- (3_1);
\draw (0_2) -- (3_2);


Let's draw the blue points and add labels to them. These labels give the text. The label position can be specified using left, right, below, and above. We can also combine them into above right.

\node[vertex, label=below:$30^\circ$] at (1_0) {};
\node[vertex, label=below:$30^\circ$] at (2_0) {};
\node[vertex, label=left:$10^\circ$] at (0_1) {};
\node[vertex, label=left:$10^\circ$] at (0_2) {};
\node[vertex, label=above right:$2$] at (2_2) {};


We should be able to fill in the rest!

Edit: As pointed out in the comments you can directly use the value of the coordinates instead of using the names, e.g., directly use (2,3) instead of (2_3). You don't need to use the double for loops for defining the coordinates as well.

• I am not sure that there is a point to giving the name (i_j) to the coordinate (i,j). What problem does it solve? Just use the coordinate (i,j) directly... Aug 29 '20 at 9:26
• Sure we can directly specify the coordinates. I wanted it to be slightly generic so that the solution can be used to solve similar problems. I commonly find myself using the same figure, with some modifications to indicate solution, drawn below the original figure. In such cases I would just offset the original coordinates in a for loop and use the same structure. Either way I wrote in a slightly tutorial style. Aug 29 '20 at 9:34

Possible Asymptote version:

// tab3x3.asy
//
// run  asy tab3x3.asy   to get   tab3x3.pdf
//
settings.tex="pdflatex";
size(4cm);
pen fillPen=rgb("E3E3E5");
pen linePen=rgb("201D1D")+0.7bp;;
pen dotPen =rgb("00A4EC")+4bp;

filldraw(box((-3,-3),(3,3)),fillPen,linePen);
guide mid=box((-1,1),(1,-1));
guide[] net=(-1,3)--(-1,-3)^^(1,3)--(1,-3)^^(-3,-1)--(3,-1)^^(-3,1)--(3,1);
draw(net,linePen);
dot(net,dotPen);

int[] labVal={10,20,30,40};
pair[][] labPos={{(-3,-1),(-3,1)},{(-1,3),(1,3)},{(-1,-3),(1,-3)},{(3,-1),(3,1)}};
pair[] labOff={W,N,S,E};

for(int i=0;i<length(mid);++i){
dot(point(mid,i),dotPen);
label("$"+string(i+1)+"$",point(mid,i),plain.NE,linePen);
}

for(int i=0;i<labVal.length;++i){
for(int j=0;j<labPos[0].length;++j){
label("$"+string(labVal[i])+"^\circ$",labPos[i][j],labOff[i]);
}
}


Another option you have is to use The Ipe extensible drawing editor. It is an editor created specifically for LaTeX that generates vectorized figures and is super practical for creating drawings like the one you want. You can export the figures as .eps, .svn, .pdf (the best choice, so that you can place the figure in your document and, if necessary, edit it later) and others. I particularly prefer it over Tikz when the goal is to create simple figures. It is a wonderful editor and you can also find some extensions for it that allow you to plot graphics, for example. In addition, you have the possibility to place packages in the preamble, being able to create whatever you want. I'm sending the image I created using the editor (about 2 minutes) and other interesting links to better understand the tool. Note that I put the dots in a darker blue because it is one of the standard colors of the application, but you can add any colors you want in the preamble.

A great and simple tutorial for ipe (if you don't want to read all the manual)

How to plot a function using IPE

Another plain, "by hand" Asymptote solution

// http://asymptote.ualberta.ca/
unitsize(1.5cm);
import math; // for grid
fill(box((0,0),(3,3)),lightgray);
string[] s={"$10^{\circ}$","$20^{\circ}$","$30^{\circ}$","$40^{\circ}$"} ;
string[] lb={"$1$","$2$","$3$","$4$",s[0],s[0],s[1],s[1],s[2],s[2],s[3],s[3]};