我正在使用 tikz 绘制一些矩形和正方形。我想在每个这样的元素附近写一个索引,并且我希望字体大小为 \tiny。我应该把 \tiny 命令放在哪里?
node[anchor=south,text=red] {
\pgfmathparse{8*\m+\v}
\tiny\pgfmathprintnumber{\pgfmathresult}
}
没有用。这是我的工作代码(使用默认字体大小):
\begin{document}
\tikzset{addition/.style={draw,circle,append after command={
[shorten >=\pgflinewidth, shorten <=\pgflinewidth,]
(\tikzlastnode.north) edge (\tikzlastnode.south)
(\tikzlastnode.east) edge (\tikzlastnode.west)
}
}
}
\tikzset{line/.style={draw, -latex',shorten <=1bp,shorten >=1bp}}
\tikzstyle{block}=[draw, rectangle, minimum size=2em]
\begin{tikzpicture}[auto]
\foreach \m in {0,1,2}{
\foreach \v in {0,1,...,7}{
\draw [red] plot [only marks, mark size=2.5, mark=*] coordinates {(2*\m, -\v)}
node[anchor=south,text=red] {
\pgfmathparse{8*\m+\v}
\pgfmathprintnumber{\pgfmathresult}
};
}
\foreach \v in {0,1,...,7}{
\draw [blue] plot [only marks, mark=square*] coordinates {(2*\m + 1,-\v)}
node[anchor=south,text=blue] {
\pgfmathparse{8*\m+\v}
\pgfmathprintnumber{\pgfmathresult}
};
}
}
\foreach \v in {0,1,...,7}{
\draw [red] plot [only marks, mark size=2.5, mark=*] coordinates {(2*3, -\v)}
node[anchor=south,text=red] {
\pgfmathparse{8*3+\v}
\pgfmathprintnumber{\pgfmathresult}
};
}
\end{tikzpicture}
\end{document}
答案1
好吧,你应该总是发布可编译的片段,因为你关于第一个片段不起作用的断言似乎是错误的。参见:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,calc}
\begin{document}
\def\m{3}\def\v{4}
\begin{tikzpicture}
\path (0,0) node[anchor=south,text=red] {
\pgfmathparse{8*\m+\v}
\tiny\pgfmathprintnumber{\pgfmathresult}
}
(1,0) node[anchor=south,text=red] {
\pgfmathparse{8*\m+\v}
\pgfmathprintnumber{\pgfmathresult}
};
\end{tikzpicture}
\end{document}
生成:
无论如何,我认为最好的方法是这样的:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,calc}
\begin{document}
\def\m{3}\def\v{4}
\begin{tikzpicture}[
my red node/.style={
anchor=south, text=red, font=\tiny
}]
\path
(0,0) node[my red node] {
\pgfmathparse{8*\m+\v}\pgfmathprintnumber{\pgfmathresult}}
(1,0) node[my red node] {
\pgfmathparse{8*\m+\v}\pgfmathprintnumber{\pgfmathresult}}
;
\end{tikzpicture}
\end{document}
答案2
font=\tiny
在您的节点选项中使用。
或者如果您希望每个节点都以小字体显示其内容,那么请使用every node/.style={font=\tiny}
您的tikzpicture
选项。