0

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
  • Please edit your post to let a complete compilable Minimal Working Example in order to get some help.
    – SebGlav
    May 5, 2021 at 16:00
  • Your document example is not compilable. Position option H is not defined (you miss to load package float).
    – Zarko
    May 5, 2021 at 17:09

2 Answers 2

1

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.

2
  • Thanks. What is the purpose of [node] that was from the template then?
    – Five9
    May 5, 2021 at 17:02
  • @Five9, if you not explicate determine, that nodes have drawn borders, than they appear without of them. This is deliberate determined nodes features.
    – Zarko
    May 5, 2021 at 17:08
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .