1

I need to write two words in each node for a tikzpicture. The probles is that the words are not displayed correctly [see the code below]: I want to write the two words inside a single node (e.g., "First Word") as two distinct words but latex writes the two words inside a single node as a single word. How can I fix this problem?

    \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}
  • Welcome to TeX.SX! Please make your code compilable (if possible). Much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. – LaRiFaRi Jul 1 '15 at 10:25
  • @LaRiFaRi The code is compilable (if not minimal). – Torbjørn T. Jul 1 '15 at 10:26
  • @TorbjørnT. oh, deleting aux files helped. But at least it is missing the float package. Thanks for your comment. – LaRiFaRi Jul 1 '15 at 10:28
  • Please consider accepting answers that you consider solved your problem by clicking the checkmark to their left. In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Sep 18 '15 at 19:43
1

You have made the matrix a matrix of math nodes, meaning that all the nodes are set in math mode, where spaces are ignored, and the text set in math italic. Change it to matrix of nodes.

enter image description here

\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}
1

Maybe it would be easier to set this with :

% 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}

By setting every cell as a node and giving it the parameter align=, you get every cell treated as text. The default would be math here.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.