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}

我使用兩個節點來編寫我正在建立的圖中的一個點的簡短解釋。然而,我必須嘗試一下設置,這樣它們就不會在垂直方向上間隔太遠,並且第二個節點以第一個節點的內容為中心。有更好的方法嗎?

在此輸入影像描述

答案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

遺憾的是,如果沒有 PSTricksparbox或其變體,PSTricks 就無法做到這一點。以下是 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}

在此輸入影像描述

相關內容