TikZ: 次のノードコンテンツを表現するより良い方法はありますか?

TikZ: 次のノードコンテンツを表現するより良い方法はありますか?

以下のコードを考えてみましょう。

\documentclass[convert = false, border = 1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[font = \scriptsize] at (-3.5, 4) {Position of $S_2$ when};
  \node[font = \scriptsize] at (-3.5, 3.7) {$S_1$ reaches $C$};
\end{tikzpicture}
\end{document}

作成中の図のポイントについて短い説明を書くために 2 つのノードを使用しました。ただし、ノードの垂直方向の間隔が離れすぎないように、また 2 番目のノードが最初のノードのコンテンツの中央に配置されるように設定を調整する必要がありました。これより良い方法はありますか?

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

答え1

Qrrbrbirlbel が指摘したように、オプションも使用すれば、\\を使用して a 内の行を分割できます。このオプションを使用しないと、 以下のトップノードに示すように効果はありません。nodealign\\

\\毎回挿入したくない場合は、text widthalignオプションを組み合わせることができます。 それらを使用すると、latexはルールに従って行を分割します。 以下にいくつかの例を示します。

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

\node[draw] (a) {Position of $S_2$ when \\ $S_1$ reaches $C$};

\node[draw,text width=3cm, below=of a] (b) {Position of $S_2$ when \\ $S_1$ reaches $C$};

\node[draw,align=center, below=of b] (c) {Position of $S_2$ when \\ $S_1$ reaches $C$};

\node[draw,text width=3cm, align=right, below=of c] (d) {Position of $S_2$ when $S_1$ reaches $C$};


\end{tikzpicture}
\end{document}

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

答え2

PSTricks またはその派生版なしではそれができないのは残念ですparbox。以下は PSTricks ありの場合です。

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}

\begin{pspicture}[showgrid](10,3)
\rput(5,2){\parbox{10cm}{\centering Karl's students do not care about dashing patterns.\\ Karl's students do not care about arrow tips.}}
\end{pspicture}

\end{document}

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

関連情報