1

How do I add text under the image below in the \begin{tikzpicture}

Dots and slopes image

\usepackage{tikz}
\usepackage[a4paper,margin=0.6in]{geometry}

\tikzset{mystyle/.style={shape=circle,fill=black,scale=0.3}}
\tikzset{withtext/.style={fill=white}}

\begin{document}
\begin{center}
\begin{figure}
\hspace{2cm}
    \begin{minipage}{.5\textwidth}
        \begin{tikzpicture}[scale=1]
            % setup the nodes
            \foreach \x in {0,...,2}
            \foreach \y in {0,...,2}
            {
            \ifnum\x=4
                \ifnum\y=4
                    \node (\x-\y) at (\x,\y){X};
                \else
                    \node[mystyle] (\x-\y) at (\x,\y){};
                \fi
            \else
                \node[mystyle] (\x-\y) at (\x,\y){};
            \fi}
            \draw (0,0) -- (0,1);
             \end{tikzpicture}
       \end{minipage}
\end{figure}
     \end{center}
\end{document}

3 Answers 3

2

Here is a tip for making the dotted grid without the loops. Use the built-in grid command:

\draw[line width=2pt, line cap=round, dash pattern=on 0pt off 1cm](0,0) grid (2,2);

The line width will specify the diameter of the dots.

enter image description here

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[line width=2pt, line cap=round, dash pattern=on 0pt off 1cm](0,0) grid (2,2);
\draw (0,0)--(0,1);
\node[below=2mm] at (1,0){Here is some text.};
\end{tikzpicture}

\end{document}
1
  • Or \node[below] at (current bounding box.south) {Here is some text.}; Commented Nov 10, 2022 at 14:55
0

Like this?

enter image description here

Your code a little bit modified:

\draw (1,-.5) node [cyan] () {This picture was made with Tikz!};
                \end{tikzpicture}
0
  • If you would consider answer on your previous question, than you should learn that your code for nodes can be much simpler.
  • Text you can add as node in path between firs and last node at bottom of nodes, i.e. as \path (0-0) -- node[below=2mm] {text below nodes} (2-0);
%\documentclass{article}
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{mystyle/.style={shape=circle,fill=black,scale=0.3}}
\tikzset{withtext/.style={fill=white}}

\begin{document}
%\begin{figure}
%    \begin{minipage}{.5\textwidth}
\begin{tikzpicture}%[scale=.5]
% setup the nodes
\foreach \x in {0,...,2}
\foreach \y in {0,...,2}
{
    \node[mystyle] (\x-\y) at (\x,\y) {};
}
\draw[semithick]    (0-0) -- (0-1);
\path   (0-0) -- node[below=2mm] {text below nodes} (2-0); % <---
\end{tikzpicture}
%       \end{minipage}
%       \end{figure}
\end{document}

enter image description here

You must log in to answer this question.

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