我遇到了一个小问题。我用 latex 创建了一个图表。这是我的代码
\[
\begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2.5cm,
semithick]
\tikzset{every state/.append style={fill=red,draw=none,text=white}}
\node[state] (A) {$\{\omega\}$};
\node[state] (B) [below=of A] {$A_{2}(1)$};
\node[state] (C) [below=of B] {$A_{1}(1)$};
\node[state] (D) [below=of C] {$\{\omega\}$};
\node[state] (F) [right=of B] {$A_{2}(2)$};
\node[state] (E) [above=of F] {$\{\omega\}$};
\node[state] (G) [below=of F] {$A_{1}(2)$};
\node[state] (H) [below=of G] {$\{\omega\}$};
\node[state] (J) [right=of F] {$A_{2}(m-1)$};
\node[state] (I) [above=of J] {$\{\omega\}$};
\node[state] (K) [below=of J] {$A_{1}(m-1)$};
\node[state] (L) [below=of K] {$\{\omega\}$};
\node[state] (M) [right=of J] {$A_{2}(m)$};
\node[state] (N) [right=of K] {$A_{1}(m)$};
\node[state] (O) [above=of M] {$\{\omega\}$};
\node[state] (P) [below=of N] {$\{\omega\}$};
\path (B) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (A)
edge [loop left] node {$\QAt$} (B)
edge node {$\QAto$} (C)
(C) edge [loop left] node {$\QAo$} (C)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (D)
edge [right] node {$\QAot$} (F)
(F) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (E)
edge [loop left] node {$\QAt$} (F)
edge node(aux) {$\QAto$} (G)
(G) edge [loop left] node {$\QAo$} (G)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (H)
(J) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (I)
edge [loop left] node {$\QAt$} (J)
edge node {$\QAto$} (K)
(K) edge [loop left] node {$\QAo$} (K)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (L)
edge [right] node {$\QAot$} (M)
(M) edge [loop left] node {$\QAt$} (M)
edge node {$\QAtw$} (O)
edge node {$\QAto$} (N)
(N) edge [loop left] node {$\QAo$} (N)
edge node {$\QAow + \QAot\mathbf{1}$} (P);
\node[right=2mm of aux,font=\bfseries\Huge]{\dots};
\end{tikzpicture}
\]
\caption{\"Ubergangsgraph von $X$}\label{Abbildung3}
\end{figure}
在哪里
\newcommand{\QAt}{\mathbf{Q}_{A_{2}A_{2}}}
\newcommand{\QAo}{\mathbf{Q}_{A_{1}A_{1}}}
\newcommand{\QAot}{\mathbf{Q}_{A_{1}A_{2}}}
\newcommand{\QAto}{\mathbf{Q}_{A_{2}A_{1}}}
\newcommand{\QAtC}{\mathbf{Q}_{A_{2}C}}
\newcommand{\QAtw}{\mathbf{Q}_{A_{2}\{\omega\}}}
\newcommand{\QAow}{\mathbf{Q}_{A_{1}\{\omega\}}}
图表如下
答案1
大部分内容与主题无关,但可能会有所帮助:
\documentclass[tikz,margin=3.141592]{standalone}
\usetikzlibrary{arrows.meta,
chains,
positioning,
quotes,
shapes.geometric}
\newcommand{\QAt}{\mathbf{Q}_{A_{2}A_{2}}}
\newcommand{\QAo}{\mathbf{Q}_{A_{1}A_{1}}}
\newcommand{\QAot}{\mathbf{Q}_{A_{1}A_{2}}}
\newcommand{\QAto}{\mathbf{Q}_{A_{2}A_{1}}}
\newcommand{\QAtC}{\mathbf{Q}_{A_{2}C}}
\newcommand{\QAtw}{\mathbf{Q}_{A_{2}\{\omega\}}}
\newcommand{\QAow}{\mathbf{Q}_{A_{1}\{\omega\}}}
\begin{document}
\begin{tikzpicture}[auto,
% scale=0.8,
% transform shape,
node distance = 15mm and 35mm, on grid,
start chain = going below,
state/.style = {ellipse, minimum height=7mm, inner xsep=0pt,
fill=red, text=white,
on chain},
every edge/.append style = {draw,-Stealth},
every loop/.append style = {looseness=4}
]
\begin{scope}[every node/.style = {state}]
\node (A) {$\{\omega\}$};
\node (B) {$A_{2}(1)$};
\node (C) {$A_{1}(1)$};
\node (D) {$\{\omega\}$};
%
\node (E) [right=of A] {$\{\omega\}$};
\node (F) {$A_{2}(2)$};
\node (G) {$A_{1}(2)$};
\node (H) {$\{\omega\}$};
%
\node (I) [right=of E] {$\{\omega\}$};
\node (J) {$A_{2}(m{-}1)$};
\node (K) {$A_{1}(m{-}1)$};
\node (L) {$\{\omega\}$};
%
\node (M) [right=of I] {$\{\omega\}$};
\node (N) {$A_{2}(m)$};
\node (O) {$A_{1}(m)$};
\node (P) {$\{\omega\}$};
\end{scope}
%
\path (B) edge ["$\mathbf{Q}_{A_{2}\{\omega\}}$"] (A)
edge [loop left,"$\QAt$"] (B)
edge ["$\QAto$"] (C)
(C) edge [loop left,"$\QAo$"] (C)
edge ["$\mathbf{Q}_{A_{1}\{\omega\}}$"] (D)
edge ["$\QAot$" '] (F)
(F) edge ["$\mathbf{Q}_{A_{2}\{\omega\}}$"] (E)
edge [loop left,"$\QAt$"] (F)
edge node (aux) {$\QAto$} (G)
(G) edge [loop left,"$\QAo$"] (G)
edge ["$\mathbf{Q}_{A_{1}\{\omega\}}$"] (H)
(J) edge ["$\mathbf{Q}_{A_{2}\{\omega\}}$"] (I)
edge [loop left,,"$\QAt$"] (J)
edge ["$\QAto$"] (K)
(K) edge [loop left,"$\QAo$"] (K)
edge ["$\mathbf{Q}_{A_{1}\{\omega\}}$"] (L)
edge ["$\QAot$" '] (N)
(M) edge [loop left,"$\QAt$"] (M)
edge ["$\QAtw$"] (N)
(N) edge ["$\QAto$"] (O)
(O) edge [loop left,"$\QAo$"] (O)
edge ["$\QAow + \QAot\mathbf{1}$"] (P);
\draw[ultra thick,loosely dotted,shorten <=2mm] (aux) -- + (1.5,0);
\end{tikzpicture}
\end{document}
我不知道,如果这张图片不宽,那么\textwidth
因为你的文档的页面布局是未知的。但是,你可以用取消注释行来调整图像宽度,scale=...
并transform shape
相应地调整图像大小:-)
答案2
太长了,无法发表评论。ellipse
确实有效。为了减少水平空间,我更改了looseness
循环的,减少了node distance
并堆叠了右下边缘标签。还要注意,循环不必要地增加了边界框,因此我手动添加了边界框。(循环的松散程度较低,问题就不那么严重了。)为了使较宽的椭圆大致相等,您可以使用inner xsep
。或者,您可以使用\makebox
es。
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,automata,positioning}
\newcommand{\QAt}{\mathbf{Q}_{A_{2}A_{2}}}
\newcommand{\QAo}{\mathbf{Q}_{A_{1}A_{1}}}
\newcommand{\QAot}{\mathbf{Q}_{A_{1}A_{2}}}
\newcommand{\QAto}{\mathbf{Q}_{A_{2}A_{1}}}
\newcommand{\QAtC}{\mathbf{Q}_{A_{2}C}}
\newcommand{\QAtw}{\mathbf{Q}_{A_{2}\{\omega\}}}
\newcommand{\QAow}{\mathbf{Q}_{A_{1}\{\omega\}}}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2cm,
semithick,
every state/.append style={fill=red,draw=none,text=white,ellipse},
every loop/.append style={looseness=5}]
\path[use as bounding box] (-2.7,0.45) rectangle (15,-10.65);
\pgfmathsetmacro{\mywidth}{(width("$A_{2}(m-1)$")-width("$A_{2}(1)$"))/4}
\node[state] (A) {$\{\omega\}$};
\node[state,inner xsep=\mywidth] (B) [below=of A] {$A_{2}(1)$};
\node[state,inner xsep=\mywidth] (C) [below=of B] {$A_{1}(1)$};
\node[state] (D) [below=of C] {$\{\omega\}$};
\node[state,inner xsep=\mywidth] (F) [right=of B] {$A_{2}(2)$};
\node[state] (E) [above=of F] {$\{\omega\}$};
\node[state,inner xsep=\mywidth] (G) [below=of F] {$A_{1}(2)$};
\node[state] (H) [below=of G] {$\{\omega\}$};
\node[state,inner xsep=-\mywidth] (J) [right=of F] {$A_{2}(m-1)$};
\node[state] (I) [above=of J] {$\{\omega\}$};
\node[state,inner xsep=-\mywidth] (K) [below=of J] {$A_{1}(m-1)$};
\node[state] (L) [below=of K] {$\{\omega\}$};
\node[state,inner xsep=\mywidth] (M) [right=of J] {$A_{2}(m)$};
\node[state,inner xsep=\mywidth] (N) [right=of K] {$A_{1}(m)$};
\node[state] (O) [above=of M] {$\{\omega\}$};
\node[state] (P) [below=of N] {$\{\omega\}$};
\path (B) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (A)
edge [loop left] node {$\QAt$} (B)
edge node {$\QAto$} (C)
(C) edge [loop left] node {$\QAo$} (C)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (D)
edge [right] node {$\QAot$} (F)
(F) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (E)
edge [loop left] node {$\QAt$} (F)
edge node(aux) {$\QAto$} (G)
(G) edge [loop left] node {$\QAo$} (G)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (H)
(J) edge node {$\mathbf{Q}_{A_{2}\{\omega\}}$} (I)
edge [loop left] node {$\QAt$} (J)
edge node {$\QAto$} (K)
(K) edge [loop left] node {$\QAo$} (K)
edge node {$\mathbf{Q}_{A_{1}\{\omega\}}$} (L)
edge [right] node {$\QAot$} (M)
(M) edge [loop left] node {$\QAt$} (M)
edge node {$\QAtw$} (O)
edge node {$\QAto$} (N)
(N) edge [loop left] node {$\QAo$} (N)
edge node[align=left] {$\hphantom{+}\QAow$\\
$+ \QAot\mathbf{1}$} (P);
\node[right=2mm of aux,font=\bfseries\Huge]{\dots};
\end{tikzpicture}
\caption{\"Ubergangsgraph von $X$.}\label{Abbildung3}
\end{figure}
\end{document}