13

enter image description here

This is the flowchart I want to draw, and there are some problems:

  1. The chart doesn't set in the center

  2. How to begin a newline of words in the rectangle and above the arrow

  3. How to make the length of arrows automatically be compatible with the length of words

  4. If possible, how to draw the arrow in the picture.

Here is my code, could you help me to modify my code to obtain the flowchart in the picture.

\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\begin{document}
\pagestyle{empty}

\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance=2cm]

\node (p1) [process] {Default protection buyer};
\node (p2) [process, right of=p1, xshift=4cm] {Default protection seller};

\draw [arrow](p1) -- node[left, pos=1] {90 basis points per year}(p2);
\draw [arrow](p2) -- node[right, pos=1] {Payment if default by reference entity}(p1);

\end{tikzpicture}
\end{document}

1 Answer 1

17

Some advice:

  1. \tikzstyle is deprecated, use \tikzset instead: Should \tikzset or \tikzstyle be used to define TikZ styles?
  2. the same for arrows library, use arrows.meta
  3. and the same also for right of=..., use right=... of: Difference between "right of=" and "right=of" in PGF/TikZ

If you set the text width of the nodes you don't need minipages, but do you use ctexart documentclass because you are obliged to? The problem is that this class set a double spacing that interferes also with the tikzpicture. I have worked around this problem setting \singlespacing for all the tikzpicture (credits to Change line spacing for normal text, but not in tabular or verse).

I have also added an argument to myarrow style, so you can position the arrow tip wherever you want.

\documentclass[UTF8]{ctexart}
\usepackage{mwe}% for testing purpose only

\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\usetikzlibrary{decorations.markings}
\tikzset{
    process/.style={
        text width=2.5cm, draw,
        minimum height=1.6cm,
        text centered,
        },
    description/.style={
        text centered,
        text width=10cm,
    },
    myarrow/.style={
        postaction={
            decorate, decoration={
                markings,mark=at position #1 with {\arrow{Stealth};
                }
            }
        }
    },
}
\usepackage{setspace}
\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\singlespacing}

\begin{document}
    \blindtext
    \pagestyle{empty}
\begin{center}
    \begin{tikzpicture}
    \node[process] (p1) {Default\\ protection\\ buyer};
    \node[process, right=16em of p1]  (p2) {Default\\ protection\\ seller};

    \draw[myarrow=.9] ([yshift=2ex]p1.east) -- node[description, above] {90 basis points per year} ([yshift=2ex]p2.west);
    \draw[myarrow=.9] ([yshift=-2ex]p2.west) -- node[description, below] {Payment if default by\\ reference entity} ([yshift=-2ex]p1.east);

    \end{tikzpicture}
\end{center}    
\blindtext
\end{document}

enter image description here

5
  • This should be the accepted answer! +1
    – Sam
    Oct 16, 2017 at 5:50
  • Great! It is clearly the better answer, so you totally deserve it.
    – Sam
    Oct 16, 2017 at 6:12
  • I think it wasn't useful anymore. Your answer contains all parts of mine and much more. You can improve his follow question too Or you can let me use your advices and answer on top of my old by using your code :P
    – koleygr
    Oct 16, 2017 at 6:27
  • if I want to set the head of arrow at the end of the line, is there a simply representation instead of calculating the length?
    – A.Oreo
    Oct 16, 2017 at 6:31
  • @A.Oreo If you want the arrow tip at the end of the line, just write \draw[-Stealth] instead of \draw[myarrow=.9]. Stealth is the kind of arrow tip, there are many others.
    – CarLaTeX
    Oct 16, 2017 at 6:34

You must log in to answer this question.

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