3

I would like to create a grid like this with tickpicture, but I don't know how to draw the points where lines match.

  • 3
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow Mar 30 '18 at 17:55
3

There might be wiser approaches, but to me it looks like something that can be solved with foreaches and manual placement of nodes.

grid

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\tikzset{dot/.style={fill=black,circle}}

\foreach\l[count=\y] in {E,...,A}
{
\draw (0,\y) -- (7.5,\y);
\node at (-0.5,\y){\l};
}

\foreach \x in {1,2,...,7}
{
\draw (\x,0) -- (\x,5.5);
\node at (\x,-0.5){\x};
}

\node[dot] at (1,5){};
\node[dot] at (2,3){};
\node[dot] at (2,4){};
\node[dot] at (3,1){};
\node[dot] at (4,4){};
\node[dot] at (5,2){};
\node[dot] at (6,3){};
\node[dot] at (7,2){};

\end{tikzpicture}
\end{document}
  • If you go about it via \foreach\x[count=\xi]in{A,...,E}{...} it travels both the letters and also keeps a counter. – percusse Mar 30 '18 at 18:34
  • Thanks for the hint, to keep it compatible with the rest of the code, I used \foreach\l[count=\y] in {E,...,A} – TobiBS Mar 30 '18 at 19:17
6

This solution allows you to place the points on the grid by referencing the indices, such as (B,2).

\documentclass[tikz, margin=2mm]{standalone}
\begin{document}
\newcommand{\mydot}[3][]{%
    \node[circle,inner sep=1.5pt,#1] at (#2 -| #3){};
}
\begin{tikzpicture}
\foreach \y[count=\iy] in {E,D,...,A}
    \draw (0,\iy) -- ++(7.5,0) node(\y)[at start,left]{\y};
\foreach \x in {1,2,...,7}
    \draw (\x,0) -- ++(0,5.5) node(\x)[at start,below]{\x};
\foreach \n/\m in {A/1,B/2,B/4,C/2,C/6,D/5,D/7}
    \mydot[fill=black]{\n}{\m};
\mydot[fill=red]{E}{3};
\end{tikzpicture}
\end{document}

enter image description here

4

I suggest you to use \filldraw[gray](x,y)circle[radius=2pt]; where (x,y) are the coordinates of the point on a grid.

Below is a sample of my code to place dots on a grid:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[main=english,frenchb]{babel}
\usepackage{tikz}
\begin{document}
\begin{figure}[h]
\begin{center}
\begin{tikzpicture}
\draw(-5.5,-5.5) grid (5.5,5.5);
\filldraw[gray](0,0)circle[radius=2pt];
\filldraw[gray](1,1)circle[radius=2pt];
\end{tikzpicture}
\caption{\label{my_grid}A grid with two points !}
\end{center}
\end{figure}
\end{document}

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.