[Tex/LaTex] TikZ Adding Text


I'm a recent convert to TikZ from xy-pic, and am still trying to get a hang for it. I see that one can add labels to the end of arrows and the like using \node. Is there a way to add an arbitrary piece of text at a given position in the text, regardless of whether there is a shape there, a line there, or nothing at all? Thanks very much for your insight.

Best Answer

In TikZ you can use nodes to place almost anything (in particular, text) in the position you want. In the following example I used the at construct to specify the exact position of the nodes using explicit coordinates:



\node[draw] at (0,0) {some text};
\node[draw,align=left] at (3,0) {some text\\ spanning three lines\\ with manual line breaks};
\node[draw,text width=4cm] at (2,-2) {some text spanning three lines with automatic line breaks};


I only used the draw option to make the nodes visible. Notice that in the second \node I used the align= key and then used the \\ command to enforce the line breaks at the desired positions. In the third \node, instead of specifying the line breaks "manually", I specified a width for the text and now the line breaking was made automatically.

enter image description here

Related Question