关于 Tikz 节点的两个问题

关于 Tikz 节点的两个问题

我看到了这个问题如何改变节点的大小?我想知道:

  1. 如果我希望节点与节点大小相同automata,我需要在尺寸处填充什么?(或比例)。
  2. 如果我想为所有节点执行此操作(我假设我需要在开始时写它),我需要写什么?

以下是 MWE:

 % Preview source code

%% LyX 2.3.1-1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[a4paper,english,hebrew,numbers=noenddot]{scrartcl}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{fontspec}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

\usepackage{tikz}
\usetikzlibrary{automata}

\makeatother

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node[state] (1) {$1$}; 
\end{tikzpicture}
\par\end{center}

\begin{center}
\begin{tikzpicture}
\draw (1,1) node[circle,draw] {$1$}; 
\end{tikzpicture}
\par\end{center}
\end{document}

谢谢你!

答案1

我对这个问题的理解与 Phelype 略有不同。如果您希望该图片中的所有节点都具有与state附带的节点相同的大小automata,则只需说every node/.append style={minimum width=2.5em}

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}
\node[state] (1) {$1$}; 
\end{tikzpicture}

\begin{tikzpicture}[every node/.append style={minimum width=2.5em}]
\draw (1,1) node[circle,draw] {$1$}; 
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

当您绘制一个 时\node [state],您就是在绘制一个\node [circle,draw,minimum size=2.5em,every state]

如何解决这个问题:

\usetikzlibrary{<library>}命令加载一个文件。在我的 TeX 发行版中tikzlibrary<library>.code.tex搜索该文件,我在 找到了它。tikzlibraryautomata.code.tex/usr/local/texlive/2018/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/

我打开文件并进行搜索state,在文件末尾发现:

\tikzstyle{state}=                [state without output]

所以state与 相同state without output。搜索后者我发现:

\tikzstyle{state without output}=  [circle,draw,minimum size=2.5em,every state]

因此,与state相同circle,draw,minimum size=2.5em,every stateevery state默认情况下为空:

\tikzstyle{every state}=           []

梅威瑟:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{document}

\begin{center}
\begin{tikzpicture}
\node[state] (1) {$1$}; 
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\draw (1,1) node [circle,draw,minimum size=2.5em,every state] {$1$}; 
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述


哦,回答你的第二个问题,你可以使用与包中大致相同的方法,但要改变样式every node。要全局更改它,你可以使用\tikzset

\tikzset{
  every node/.style = {
    circle,draw,minimum size=2.5em,every state
  }
}

或者,对于单个tikzpicture,您可以将其作为选项传递:

\begin{tikzpicture}[
  every node/.style = {
    circle,draw,minimum size=2.5em,every state
  }
]
\draw (1,1) node {$1$}; 
\end{tikzpicture}

答案3

这是将大小设置state为已知值的最小示例。

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{document}
\begin{center}
\begin{tikzpicture}[every state/.style={minimum size=2cm},]
\node[state] (1) {$1$}; 
\end{tikzpicture}

\begin{tikzpicture}
\draw (1,1) node[circle,draw,minimum size=2cm] {$1$}; 
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容