異なる有向グラフ

異なる有向グラフ

希望のグラフ

上の図のようなグラフを作成する必要がありますが、矢印なしの水平線や垂直矢印の描き方がわかりません。私ができる最善のことは、次のとおりです。

\documentclass{amsart}
\usepackage{tikz} 
\begin{document}
\begin{center}
\begin{tikzpicture}
    \node (p1) at ( 0, 0) {}; 
    \node (p2) at ( 1, -0.2) {i};
    \node (p3) at ( 3,0) {};
    \node (p4) at ( 0,1) {};
    \node (p5) at ( 2,1.2) {n+j};
    \node (p6) at ( 3,1) {};
    \begin{scope}[every path/.style={->}]
       \draw (p1) -- (p3); 
       \draw (p4) -- (p6);
       \draw (p2) -- (p5);
    \end{scope}  
\end{tikzpicture}
\end{center}
\end{document}

出力

ここに画像の説明を入力してください

答え1

これは望ましい結果でしょうか:

ここに画像の説明を入力してください

ノート:

  • 線の端に矢印の先端を付けたくない場合は、スタイルを変更するかevery path/.style={-}、以下で行ったようにそのオプションを単に削除します。デフォルトでは、線には矢印の先端は付きません。
  • 希望する矢印のスタイルは です-latex。したがって、必要なときにそのオプションを追加するだけです (オレンジ色の線の場合など)。
  • shorten <=とを追加してshorten >=オレンジ色の線を延長します。または、手動でポイントを選択することもできます。の上この線。
  • このcalcライブラリは、coordinate垂直の黒い線を描画する中間点を計算するために使用されました。
  • を追加してノード ラベルを数式モードにしました$
  • どの描画コマンドが何を実行しているかを簡単に把握できるように色が追加されました。

コード:

\documentclass{amsart}
\usepackage{tikz} 
\usetikzlibrary{calc}
\begin{document}
\begin{center}
\begin{tikzpicture}[thick]
    \node (p1) at ( 0, 0) {}; 
    \node (p2) at ( 1, -0.2) {$i$};
    \node (p3) at ( 3,0) {};
    \node (p4) at ( 0,1) {};
    \node (p5) at ( 2,1.2) {$n+j$};
    \node (p6) at ( 3,1) {};
    \coordinate (p1MidwayP3) at ($(p1)!0.5!(p3)$);
    \coordinate (p4MidwayP6) at ($(p4)!0.5!(p6)$);
    \begin{scope}%[every path/.style={-}]
       \draw [red] (p1) -- (p3); 
       \draw [blue] (p4) -- (p6);
       \draw [orange, shorten <=-0.08cm, shorten >=-0.10cm, -latex](p2) -- (p5);
       \draw  (p1MidwayP3) -- (p4MidwayP6);
    \end{scope}  
\end{tikzpicture}
\end{center}
\end{document}

答え2

PSTricksソリューションと組み合わせるとxfp:

\documentclass{article}

\usepackage{pstricks-add}
\usepackage{xfp}

\begin{document}

\def\Horizontal{5} % length of the horizontal line segments
\def\Vertical{3}   % length of the vertical   line segment
\def\Indent{0.5}   % indentation of the arrow from both sides
\begin{pspicture}(0,-0.4)(\Horizontal,\fpeval{\Vertical+0.45})
  \psline(0,0)(\Horizontal,0)
  \psline(0,\Vertical)(\Horizontal,\Vertical)
  \psline(\fpeval{\Horizontal/2},0)(\fpeval{\Horizontal/2},\Vertical)
  \psline{->}(\Indent,0)(\fpeval{\Horizontal-\Indent},\Vertical)
  \uput[270](\Indent,0){$i$}
  \uput[90](\fpeval{\Horizontal-\Indent},\Vertical){$n+j$}
\end{pspicture}

\end{document}

出力

\Horizontal、、の値を選択するだけで\Vertical\Indentそれに応じて描画が調整されます。

関連情報