如何在下图中添加文字\begin{tikzpicture}
\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}
答案1
以下是制作不带环的虚线网格的技巧。使用内置grid
命令:
\draw[line width=2pt, line cap=round, dash pattern=on 0pt off 1cm](0,0) grid (2,2);
将line width
指定点的直径。
\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}
答案2
答案3
- 如果您考虑回答上一个问题,那么您应该了解到节点代码可以更简单。
- 您可以在节点底部的第一个节点和最后一个节点之间的路径中添加文本作为节点,即
\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}