5

enter image description here

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

7
  • What does it represent? Why did you choose the biblatex tag?
    – AndréC
    Aug 29, 2020 at 5:48
  • I tried to just tag "LaTex" it's for my linear algebra HW and it's a temperature graph. Aug 29, 2020 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?
    – AndréC
    Aug 29, 2020 at 6:53
  • 1
    Therefore, the simple reproduction of this graphic is suitable for you.
    – AndréC
    Aug 29, 2020 at 7:35
  • 1
    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".
    – Marvin
    Aug 29, 2020 at 8:43

5 Answers 5

11

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.

screenshot

\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}
6

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) {};

Figure generated from code. Coordinate figure.

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.

2
  • 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, 2020 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.
    – Marvin
    Aug 29, 2020 at 9:34
5

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]);
  }
}

enter image description here

2

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.

enter image description here

Another links:

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

How to plot a function using IPE

Ipelets to improve your editor

0

Another plain, "by hand" Asymptote solution

enter image description here

// http://asymptote.ualberta.ca/
unitsize(1.5cm);
import math; // for grid
fill(box((0,0),(3,3)),lightgray);
add(grid(3,3));
pair[] pts={(1,2),(2,2),(2,1),(1,1),(0,1),(0,2),(1,3),(2,3),(3,1),(3,2),(2,0),(1,0)};
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]};
pair[] a={NE,NE,NE,NE,W,W,N,N,E,E,S,S};

for(int i=0; i<pts.length; ++i){
fill(circle(pts[i],.06),magenta);
label(lb[i],align=a[i],pts[i]);
}

shipout(bbox(5mm));

You must log in to answer this question.

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