人生の人生

日常のゴミ捨て場

TikZなんて使わないほうが良いよ

TikZはクソ.
フローチャートをTikZで描こうと頑張ったときのメモです.
フローチャートの内容は気にしないでください.

フローチャートその1

\documentclass[10pt, a4paper]{ltjsarticle}
\usepackage{luatex-ja}
\usepackage{tikz}
\usetikzlibrary{fit, positioning, shapes.geometric, decorations.pathreplacing}
\begin{document}

\begin{figure}[htbp]
  \centering
  \begin{tikzpicture}[node distance=1.5\zh, auto]
    \tikzstyle{decis} = [draw, diamond, aspect=3, text width=7\zw, align=flush center, inner sep=0pt]
    \tikzstyle{block} = [draw, rectangle, text width=8\zw, align=center, minimum height=3\zh]
    \tikzstyle{line} = [draw, -latex]

    % Place nodes
    \node [block] (grad) {勾配の計算\\ 式ほげ};
    \node [block, below=of  grad] (recon) {物理量の再構築\\ 式ほげ};
    \node [block, below=of recon] (invis) {非粘性流束の評価\\ 式ほげ};
    \node [block, below=of invis] (visc) {粘性流束の評価\\ 式ほげ};
    \node [inner xsep=0.5\zw, inner ysep=0.5\zh, fit=(grad) (recon) (invis) (visc)] (box) {};
    \node [block, node distance=1.5cm, left=of box] (calcrhs) {右辺項の計算};
    \node [block, above=of calcrhs] (calcdt) {時間刻み幅の計算\\ 式ほげ};
    \node [block, above=of  calcdt] (init)   {初期化};
    \node [block, above=of    init] (input)  {計算条件の入力};
    \node [block, below=of calcrhs] (updvar) {保存変数の更新};
    \node [decis, below=of  updvar] (isconv) {収束?};
    \node [block, below=of  isconv] (output) {計算結果の出力};
    % Draw edges
    \path [line]    (grad) -- (recon);
    \path [line]   (recon) -- (invis);
    \path [line]   (invis) -- (visc);
    \draw [decorate, decoration={brace, amplitude=1.3cm}] (box.south west) -- (box.north west);
    \path [line]   (input) -- (init);
    \path [line]    (init) -- (calcdt);
    \path [line]  (calcdt) -- (calcrhs);
    \path [line] (calcrhs) -- (updvar);
    \path [line]  (updvar) -- (isconv);
    \path [line]  (isconv) -- node [, color=black] {yes} (output);
    \path [line]  (isconv.west) -- +(-1cm, 0) node [near start, color=black] {no} |- (calcdt);
  \end{tikzpicture}
  \caption{TikZによるフローチャートの描画の例その1.}
\end{figure}

\end{document}

f:id:sktakefumi:20191229220430p:plain
フローチャートその1.

詰まったところ:

Simple flow chart | TikZ example

    • node distance=1.5\zh, auto が便利だと知った
  • 上のページで位置指定に使われている below of=init はdeprecatedらしい
    • かわりにこっち.\usetikzlibrary{positioning}が必要

TikZ でノードを相対位置で配置する話 - マクロツイーター

  • コの字型の矢印の出し方
    • ここ

Tikz: How to create arrow with two corners? - TeX - LaTeX Stack Exchange

  • 右の4つのノードをまとめて,"右辺項の計算"の右に位置させる
    • 下記コードで見えない箱を作って,その左に"右辺項の計算"を置いた
    \node [inner xsep=0.5\zw, inner ysep=0.5\zh, fit=(grad) (recon) (invis) (visc)] (box) {};
    • 下記のグループ機能を使った方がスマート?

Positioning groups of tikz nodes relative to their centre - TeX - LaTeX Stack Exchange

  • デカい中かっこ
    • このへん.\usetikzlibrary{decorations.pathreplacing}が必要

Draw Curly Braces in TikZ - TeX - LaTeX Stack Exchange

フローチャートその2

\documentclass[10pt, a4paper]{ltjsarticle}
\usepackage{luatex-ja}
\usepackage{tikz}
\usetikzlibrary{fit, positioning, shapes.geometric, decorations.pathreplacing}
\begin{document}

\begin{figure}[htbp]
  \centering
  \begin{tikzpicture}[node distance=1.5\zh, auto]
    \tikzstyle{decis} = [draw, diamond, aspect=3, text width=7\zw, align=flush center, inner sep=0pt]
    \tikzstyle{block} = [draw, rectangle, text width=7\zw, align=center, minimum height=3\zh]
    \tikzstyle{line} = [draw, -latex]
    % Place nodes
    \node [block] (input) {計算条件\&形状の入力};
    \node [block, below=of input]   (init) {初期格子};
    \node [block, below=of init]   (fcalc) {流体計算};
    \node [decis, below=of fcalc]  (isamr) {AMR?};
    \node [block, below=of isamr] (output) {計算結果の出力};
    \node [block, node distance=3\zw, right=of isamr] (amrprm) {AMR指標\\ の計算};
    \node [block, right=of amrprm]  (eval) {セルの評価};
    \node [block]  (regen) at (fcalc -| eval)  {格子の再作成};
    \node [block] (interp) at (fcalc -| amrprm) {物理量の補完};
    % Draw edges
    \path [line]  (input) -- (init);
    \path [line]   (init) -- (fcalc);
    \path [line]  (fcalc) -- (isamr);
    \path [line]  (isamr) -- node [near start, color=black] {yes} (amrprm);
    \path [line]  (isamr) -- node [, color=black] {no} (output);
    \path [line] (amrprm) -- (eval);
    \path [line] (eval.east) -- +(1, 0) |- (regen.east);
    \path [line]  (regen) -- (interp);
    \path [line] (interp) -- (fcalc);
  \end{tikzpicture}
  \caption{TikZによるフローチャートの描画の例その1.}
\end{figure}
\end{document}

f:id:sktakefumi:20191229220427p:plain
フローチャートその2.

詰まったところ:

  • "物理量の補完"を"AMR指標の計算"の上かつ"流体計算"の右に置く
    • ここ

tikz: positioning above of point a, left of point b - TeX - LaTeX Stack Exchange

    • at (fcalc -| eval) なんて書き方があるのね