TransWikia.com

Rectangular nodes in Tikz Automata has no outline

TeX - LaTeX Asked by Five9 on July 6, 2021

Will preface by saying I’m very unfamiliar with Tikz and I just edited a template.
The template was for a state diagram when I wanted to draw Markov chains.
Now, I want square nodes instead of circles because I’m doing something different; the text need causes the circle to be way too huge. I would rather have a rectangle.

I have:

documentclass[a4paper, 12pt, fleqn]{article}
usepackage{tikz} 
usetikzlibrary{automata, positioning, shapes}

being{document}

begin{figure}[H]
    centering
    begin{tikzpicture}[node distance=6.5cm, auto]
       node[state] (TL) {$102$ JPY/USD}; 
       node[state, accepting] (BL) [below of=TL] {$(1+r_{USD})$ USD};
       node[rectangle] (TR) [right of=TL] {$102$ JPY};
       node[state] (BR) [below of=TR] {$(1+r_{JPY})$ JPY};
 
       path[->]
        (TL) edge node {$1 text{USD} times 102 text{JPY}$} (TR)
        (TL) edge node {$r_{USD}$} (BL)
        (TR) edge node {$r_{JPY}$} (BR)
        (BR) edge [bend left] node {$1 text{USD} times 102 text{JPY}$} (BL)
       ;
    end{tikzpicture}
    caption{Covered Interest Rate Parity}
 end{figure}

end{document}

But the TR node does not have an outline around it. I tried a bunch of different keywords I found around google, but only "node" seems to work. Is there no simple keyword option that can get me a rectangle?

2 Answers

Add "draw" to "rectangle" to the options of node:

...
node[rectangle, draw] (TR) [right of=TL] {$102$ JPY};
...

By default tikz does not draw the nodes.

Correct answer by Sergio Llorente on July 6, 2021

I would draw your image on the following way:

  • define all nodes style used in diagram
  • use position syntax as defined in position package
  • enable multi (two) line text in nodes
documentclass[a4paper, 12pt, fleqn]{article}
usepackage{tikz}
usetikzlibrary{arrows.meta, automata, 
                positioning, 
                quotes}
usepackage{amsmath}
usepackage[low-sup]{subdepth}

begin{document}
    begin{figure}[ht]
    centering
    begin{tikzpicture}[
      node distance = 44mm and 66mm, on grid,
state/.append style = {semithick, align=center, inner sep=1pt},
         rct/.style = {draw},
  every edge/.style = {draw, -Straight Barb, semithick},
every edge quote/.style = {auto, font=small}
                        ]
node[state] (TL) {102 JPY/USD};
node[state, accepting] (BL) [below=of TL] {$(1+r_{text{USD}})$ USD};
node[rct]   (TR) [right=of TL] {102 JPY};
node[state] (BR) [below=of TR] {$(1+r_{text{JPY}})$ JPY};
%
path   (TL) edge ["$1,text{USD} times 102,text{JPY}$"] (TR)
        (TL) edge ["$r_{text{USD}}$"] (BL)
        (TR) edge ["$r_{text{JPY}}$"] (BR)
        (BR) edge [bend left, "$1,text{USD} times 102,text{JPY}$"] (BL)
        ;
    end{tikzpicture}
caption{Covered Interest Rate Parity}
    end{figure}
end{document}

enter image description here

Note: In node style is usually defined:

  • type of shape (rectangle, circle, ellipse, etc)
  • shape of border (draw, thickens of lines)
  • size (width, height)
  • separation between text and border and border and surrounding
  • etc.
  • Some of this attributes have default values (as inner sep, outer sep)
  • for details see TikZ and PGF manual, chapter 17 Nodes and Edges

Answered by Zarko on July 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP