'to'操作について知っているTikZ'midway '

Nov 29 2020

これは、これと同じ/フォローアップのようなものです:最後の「現在の座標」を参照するTikZ座標

その質問への答えto--、私が使用\tikztostartしようとするまで正常に機能する「現在の座標」を参照するために使用できるように、代わりに使用することを提案していますnode[midway]。元の例を拡張します。

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
 \coordinate (origin) at (0,0);
 \draw (origin) -| (1,1) -- (1,1-|origin) % this uses --
   node [midway,above] {hi};
 \begin{scope}[xshift=2cm]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (1,1) to (\tikztostart-|origin) % this uses to
    node [midway,above] {hi};
 \end{scope}
\end{tikzpicture}
\end{document}

出力(左側が正しい):

前のパスセグメントmidwayについて知らずtomidwayから取っているように見えます。

midwayノードをtoサブパスに接続することになっていることをどのように知ることができますか?または、このケースに対処する私の前の質問に対する別の答えはありますか?

回答

3 M.AlJumaily Nov 29 2020 at 11:00

Ti k Zlingによって与えられた答えは素晴らしいです、そしてさらに、私たちは単に\node[]{...}:からの順序を入れ替えることができます

\draw (origin) -| (1,1) to (\tikztostart-|origin) node [midway,above] {hi};

\draw (origin) -| (1,1) to node [midway,above] {hi} (\tikztostart-|origin);

midwayTi k Zがデフォルトでパスの中央、間に挟まれた2つの座標の間で調整するので、取り出すこともできます。

\draw (origin) -| (1,1) to node [above] {hi} (\tikztostart-|origin);

もう1つのヒントはpos、正確な配置のために0.0〜1.0の10進引数を受け入れるキーを使用することです。

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
 \coordinate (origin) at (0,0);
 \draw (origin) -| (1,1) -- (1,1-|origin)
   node [midway,above] {hi};
 \begin{scope}[xshift=2cm]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (2,1) to node [above] {hi} (\tikztostart-|origin);
 \end{scope}
  \begin{scope}[xshift=5cm]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (2,1) to node [pos=0.25, above] {hi} (\tikztostart-|origin);
 \end{scope}
\end{tikzpicture}
\end{document}
3 Noname Nov 29 2020 at 10:54

あなたの観察は正しいです。M. Al Jumailyによるコメントがすでにあり、1つの可能な解決策を示しています。別の解決策は、傾斜したパスにもエッジラベルを適切に配置するため、間違いなくより便利ですが、edge labelキーを使用することです。発生する問題は、とは関係\tikztostartがなく、実際にはとのみ関係があることに注意してくださいto

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
 \begin{scope}[local bounding box=1]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (1,1) -- (1,1-|origin)
    node [midway,above] {hi};
 \end{scope}  
 \begin{scope}[xshift=2.5cm,local bounding box=2]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (1,1) coordinate (tmp) to (tmp-|origin)
   node [midway,above] {hi};
 \end{scope}
 \begin{scope}[xshift=5cm,local bounding box=3]
  \coordinate (origin) at (0,0);
  \draw (origin) -| (1,1) to[edge label'={hi}] (\tikztostart-|origin);
 \end{scope}
 %
 \path foreach \X [count=\Y] in {--,to,to w/ edge label}
 {(\Y.south) node[below=1em,font=\sffamily]{\X}};
\end{tikzpicture}
\end{document}