12

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

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

  • This should be the accepted answer! +1 – Sam Oct 16 '17 at 5:50
  • @Sam Thank you! But I wrote it after that the other one was accepted. :) – CarLaTeX Oct 16 '17 at 5:52
  • 1
    @Sam Now I've stolen the tick :) – CarLaTeX Oct 16 '17 at 6:06
  • Great! It is clearly the better answer, so you totally deserve it. – Sam Oct 16 '17 at 6:12
  • @koleygr Thank you, but it was not necessary to delete yours :):):) – CarLaTeX Oct 16 '17 at 6:23

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.