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.

I want to draw two text nodes in tikz-figure where the text is aligned left and not centered:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \node at (1.0, 2.0) {veeeeeeeeeeery long text node};
    \node at (1.0, 1.0) {short text node};
  \end{tikzpicture}
\end{figure}

\end{document}

Here, the positions define the center of the text. What I want to do is to specify the left position of text. Who to do this?

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

If I understand correctly, you want the text in the nodes to appear left-aligned. You can use the anchor option that tells TikZ which one of the node's anchors to place at the specified coordinates:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [anchor=west] at (1.0, 2.0) {veeeeeeeeeeery long text node};
\node [anchor=west] at (1.0, 1.0) {short text node};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
I've added the picture obtained. I hope you don't mind :). –  Claudio Fiandrino Aug 11 '12 at 12:28
    
@Claudio Should have done it myself, thanks. –  Baldrick Aug 11 '12 at 13:17
add comment

This is quite easy: just use \node[right] to tell TikZ to fraw the nodes rightward from the specified position:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \node[right] at (1.0, 2.0) {veeeeeeeeeeery long text node};
    \node[right] at (1.0, 1.0) {short text node};
  \end{tikzpicture}
\end{figure}

\end{document}

enter image description here


If you want the texts not that far apart, you can do it without trying by using named nodes for referencing:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \node[right,inner sep=0,minimum height=0.6cm] (a) at (1.0, 2.0) {veeeeeeeeeeery long text node};
    \node[below right,inner sep=0,minimum height=0.6cm] (b) at (a.south west) {short text node};
    \node[below right,inner sep=0,minimum height=0.6cm] (c) at (b.south west) {another text node};
    \node[below right,inner sep=0,minimum height=0.6cm] (d) at (c.south west) {yet another text node};
  \end{tikzpicture}
\end{figure}

\end{document}

enter image description here


If you use the align=<key> option for the node, you can also use \\ inside the node for line breaking, thus putting all the content in a single node:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \node[align=left] {veeeeeeeeeeery long text node\\ short text node\\ another text node\\yet another text node};
  \end{tikzpicture}
\end{figure}

\end{document}

enter image description here


If it does not matter where the line breaks occur, you can use the text width=<length> option to automatically break the text:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \begin{tikzpicture}
    \node[text width=5cm] {veeeeeeeeeeery long text node; short text node; another text node; yet another text node};
  \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

share|improve this answer
add comment

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.