Tikzpicture 和 \matrix 的问题

Tikzpicture 和 \matrix 的问题

我需要在每个节点中为 tikzpicture 写入两个单词。问题是这些单词无法正确显示 [参见下面的代码]:我想将单个节点内的两个单词(例如“First Word”)写为两个不同的单词,但 latex 将单个节点内的两个单词写为一个单词。我该如何解决这个问题?

    \documentclass{article} 
    \usepackage{amssymb}
    \usepackage{moresize}
    \usepackage{amsmath}   
    \usepackage{setspace} 
    \usepackage{amsthm}
    \usepackage{soul}
    \usepackage{mathtools}
    \usepackage{appendix}
    \usepackage{tikz}
    \usetikzlibrary{arrows,chains,matrix,positioning,scopes}
    \begin{document}
    \fontsize{11}{13}\selectfont 

    \begin{figure}[H]
    \caption{} 
    \centering
   \begin{tikzpicture}
         \matrix (m) [matrix of math nodes, row sep=2em,
      column sep=2em]
       { First Word   &  & Second Word  \\
       & Third  Word   &  \\ };
      \path[->,font=\large, ultra thick]
       (m-1-1) edge node[auto] {$ a $} (m-1-3); 
      \path[->,font=\large, ultra thick]
       (m-1-1) edge node[auto] {$ b $} (m-2-2);
       \path[->,font=\large, ultra thick]
        (m-2-2) edge node[auto] {$ c $} (m-1-3);
        \end{tikzpicture}
         \label{fig:fig1}
        \end{figure}

         \end{document}

答案1

您已将矩阵设为matrix of math nodes,这意味着所有节点都设置为数学模式,其中空格被忽略,文本设置为数学斜体。将其更改为matrix of nodes

在此处输入图片描述

\documentclass[border=3mm]{standalone} 
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
 \matrix (m) [matrix of nodes, row sep=2em,
  column sep=2em]
   { First Word   &  & Second Word  \\
   & Third  Word   &  \\ };
  \path[->,font=\large, ultra thick]
   (m-1-1) edge node[auto] {$ a $} (m-1-3); 
  \path[->,font=\large, ultra thick]
   (m-1-1) edge node[auto] {$ b $} (m-2-2);
   \path[->,font=\large, ultra thick]
(m-2-2) edge node[auto] {$ c $} (m-1-3);
\end{tikzpicture}
\end{document}

答案2

也许这样设置会更容易

% arara: pdflatex

\documentclass{article} 
\usepackage{float} % for your [H] option to figure (I guess)
\usepackage{caption} % for better spacing if captions are used above the figures. And it deletes the colon if no caption is given.
\usepackage{tikz-cd}

\begin{document}
\fontsize{11}{13}\selectfont 
\begin{figure}[H]
    \caption{}\label{fig:fig1} 
    \centering
    \begin{tikzcd}[%
        ,cells={nodes={align=center}} % this line switches from math to text for the nodes. You can align left or right as well if more lines of text exist
        ,every arrow/.append style={->,ultra thick}
        ,every label/.append style={font=\large}
        ,row sep=6ex
        ]
    First Word \arrow{rr}{a} \arrow{dr}[swap]{b} & & Second Word \\
    & Third Word \arrow{ur}[swap]{c} & % I swapped two labels in order to set them to the outer side
   \end{tikzcd}         
\end{figure}        
\end{document}

通过将每个单元格设置为节点并为其提供参数align=,您可以将每个单元格视为文本。此处的默认值为数学。

在此处输入图片描述

相关内容