tikzpicture 中的换行符

tikzpicture 中的换行符

如何让 q5 到 qA 的边缘分成两条线?我看了其他帖子,似乎都没什么用。

编辑:添加宏和格式

%==============================================================================
% Homework X, CS 254 (Fall 2020)
%
% Fill out this information for every assignment. This template has been adapted from one by Layla Oesper.
%==============================================================================
\newcommand{\thishw}{\bf Homework 6}
\newcommand{\myname}{}  % Your name here.
\newcommand{\timespent}{}
\newcommand{\mypair}{}  % Your homework pair, including you.
\newcommand{\mygroup}{}  % Your homework group, including you.
\newcommand{\mycredit}{None} 
%==============================================================================
% Formatting parameters.
%==============================================================================

\documentclass[11pt]{article} % 11pt article, want AMS fonts.
\makeatletter                   % Make '@' accessible.
\pagestyle{myheadings}              % We do our own page headers.
\def\@oddhead{\bf CS 254 - \thishw{} \hfill \myname } % Here they are.
%\def\thesection{Component\hskip-1em\ }     % Section headlines.
\oddsidemargin=0in              % Left margin minus 1 inch.
\evensidemargin=0in             % Same for even-numbered pages.
\textwidth=6.5in                % Text width (8.5in - margins).
\topmargin=0in                  % Top margin minus 1 inch.
\headsep=0.2in                  % Distance from header to body.
\textheight=8in                 % Body height (incl. footnotes)
\skip\footins=4ex               % Space above first footnote.
\hbadness=10000                 % No "underfull hbox" messages.
\makeatother                    % Make '@' special again.
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

%==============================================================================
% Import Packages.  You can add anything you need here.
%==============================================================================

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{latexsym}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows}
\graphicspath{ {./images/} }

%==============================================================================
% Macros.
%==============================================================================
\newcommand{\component}[1]{\section*{Component #1}}     % Component.
\newcommand{\challenge}[1]{\section*{Supplementary Challenge #1}}       % Supplementary challenge.
\newcommand{\totaltime}[1]{\subsection*{Time spent} \timespent} % Time spent
\newcommand{\hwpair}{\subsection*{Homework Pair} \mypair } % Homework pair.
\newcommand{\hwgroup}{\subsection*{Homework Group} \mygroup} % Homework group.
\newcommand{\credit}{\subsection*{Other Credit} \mycredit} % Other people to credit.         

%==============================================================================
% Title, time spent and collaborations.
% Note: You shouldn't edit this section.
%==============================================================================

\begin{document}
\centerline{\LARGE\thishw{}}

\vskip1em
\noindent \fbox{\begin{minipage}{\textwidth}

\totaltime 

\hwpair

\hwgroup

\credit

\end{minipage}
}

%%%%%%%%%%%%%%%%%%%%  COMPONENT 1  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{1}

Note: I will be using \_ to indicate blank space. I am also making the assumption that $i > 0, j > 0, k > 0$.

    \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm, thin,main node/.style={circle,draw,font=\sffamily}]
    
      \node[main node] (0) {$q_0$};
      \node[main node] (1) [right of=0] {$q_1$};
      \node[main node] (2) [right of=1] {$q_1$};
      \node[main node] (3) [above right of=2] {$q_2$};
      \node[main node] (4) [right of=3] {$q_3$};
      \node[main node] (5) [below right of=2] {$q_4$};
      \node[main node] (6) [right of=5] {$q_5$};

      \node[main node] (7) [above right of=6] {$q_A$};

      \path[every node/.style={font=\sffamily\small}]
        (0) edge node [above] {$\epsilon, \epsilon$;z} (1)
        (1) edge node [above] {C,$\epsilon$;c} (2)
        (2) edge [loop right] node {C,$\epsilon$;c} (2)
            edge node [left] {A,c;$\epsilon$} (3)
            edge node [left] {A,$\epsilon$;a} (5)
        (3) edge [loop above] node {A,c;$\epsilon$} (3)
            edge node [above] {A,z;$\epsilon$} (4)
            edge node [below] {T,c;$\epsilon$} (7)
        (4) edge [loop above] node {A,$\epsilon$;$\epsilon$} (4)
            edge node [right] {T,$\epsilon$;$\epsilon$} (7)
        (5) edge [loop below] node {A,$\epsilon$;a} (5)
            edge node [below] {T,a;$\epsilon$} (6)
        (6) edge [loop below] node {T,a;$\epsilon$} (6)
            edge node [below] {T,c;$\epsilon$\\ \_,a;$\epsilon$} (7);
    \end{tikzpicture}

We cannot create a deterministic version of this PDA because it is not possible to check that $i \ne j$ and $j \ne k$ at the same time.

\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 2  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{2}
\begin{enumerate}
    \item
    \item
    \item
\end{enumerate}

\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 3  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{3}


\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 4  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{4}

\begin{enumerate}
    \item [\textbf{10.5:}]
    \item [\textbf{10.7}]
\end{enumerate}


\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 5  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{5}

\begin{enumerate}
    \item [\textbf{10.6:}]
\end{enumerate}

\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 6  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{6}

\begin{enumerate}
    \item [\textbf{10.15:}]
\end{enumerate}


\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 7  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{7}

\begin{enumerate}
    \item [\textbf{11.6:}]
\end{enumerate}

\newpage

%%%%%%%%%%%%%%%%%%%%  COMPONENT 8  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\component{8}

\begin{enumerate}
    \item [\textbf{11.9:}]
\end{enumerate}

\newpage

%%%%%%%%%%%%%%%%%%%% SUPPLEMENTARY CHALLENGE 1  %%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\challenge{1}

\begin{enumerate}
    \item [11.7]
\end{enumerate}

\newpage


\end{document}

图形

答案1

根据您的文档示例,我制作了以下 MWE(最小工作示例):

\documentclass [margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
           node distance = 20mm, on grid,
       every edge/.style = {draw, -Stealth, shorten >=1pt}, 
every edge quotes/.style = {auto,
                            font=\sffamily\small\linespread{0.84}\selectfont,
                            inner sep=2pt, align=center},
     state/.append style = {minimum  size=1.5em, inner sep=2pt}
                        ]
    \begin{scope}[nodes={state}]
\node (0) {$q_0$};
\node (1) [right=of  0] {$q_1$};
\node (2) [right=of  1] {$q_1$};
\node (3) [above right=of  2] {$q_2$};
\node (4) [right=of  3] {$q_3$};
\node (5) [below right=of  2] {$q_4$};
\node (6) [right=of  5] {$q_5$};
\node (7) [above right=of  6] {$q_A$};
    \end{scope}
\path   (0) edge ["{{$\epsilon, \epsilon$;z}}"] (1)
        (1) edge ["{C,$\epsilon$;c}"] (2)
        (2) edge [loop right,"{C,$\epsilon$;c}"] (2)
            edge ["{A,c;$\epsilon$}"] (3)
            edge ["{A,$\epsilon$;a}" '] (5)
        (3) edge [loop above,"{A,c;$\epsilon$}"] (3)
            edge ["{A,z;$\epsilon$}"] (4)
            edge ["{T,c;$\epsilon$}" '] (7)
        (4) edge [loop above,"{A,$\epsilon;\epsilon$}"] (4)
            edge ["{T,$\epsilon;\epsilon$}"] (7)
        (5) edge [loop below,"{A,$\epsilon$;a}"] (5)
            edge ["{T,a;$\epsilon$}" '] (6)
        (6) edge [loop below,"{T,a;$\epsilon$}"] (6)
            edge ["{T,c;$\epsilon$\\ \_,a;$\epsilon$}" '] (7);
    \end{tikzpicture}
\end{document}

编译后产生:

在此处输入图片描述

在 MWE 中与您的文档示例相比,进行了以下更改:

  • 由于只关注图像,standalone因此使用了仅显示图像的文档类。但是,它对任何文档中图片代码的使用没有任何影响
  • 增加了两个库:automatapositioningarrows替换为arrows.meta
  • 顶点定位使用库定位中的语法(注意现在=of互换),它定义节点边界之间的距离,
  • 顶点(节点)位于网格上
  • 代码被分组scope,这样可以编写更短的代码
  • 而不是edge notes使用边引号。为它们定义了新样式 ( every edge quotes,它会自动将标签定位在边缘的左侧,但是,图中有四个例外,其中定位使用swap选项(实际上是它的缩写'
  • 重新定义了使用样式 (state而不是main node, 样式作为边节点。

希望所显示的结果正是您所期望的。

相关内容