Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the code below:

\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}

I used two nodes to write short explanation of a point in a figure I am constructing. However, I had to play around with the set up so they weren't spaced vertically too far a part and the second node was centered on the content of the first node. Is there a better way to this?

enter image description here

share|improve this question
3  
Yes, \node […,align=center] at (…) {Position of $S_2$ when \\ $S_1$ reaches $C$};. –  Qrrbrbirlbel Jul 11 '13 at 22:55
    
@Qrrbrbirlbel thanks. I didn't know I could use \\ in a node. –  dustin Jul 11 '13 at 23:00

2 Answers 2

up vote 7 down vote accepted

As Qrrbrbirlbel pointed, you can use \\ to break lines inside a node if you also use align option. Without it, \\ has no effect as is shown in top node below.

If you don't want to insert \\ every time, you can combine text width and align options. With them, latex will break lines according its rules. You'll find some examples below.

\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}

enter image description here

share|improve this answer

It is sad that PSTricks cannot do it without parbox or its variants. The following is with 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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.