6

My simple question is how to set some text using tikz in a column e.g.

+---+
| A |
| B |
| C |
+---+

I do not want to rotate the text so I can not use the rotate option or the set text along path method. Can give me a hint how to do it right?

  • Using a matrix and populating the rows with letters maybe? – percusse Aug 18 '11 at 13:08
  • Then I need the size and position of the whole matrix. – Christian Wolf Aug 18 '11 at 13:24
  • 3
    Just about anything can go in a \node text so you could achieve this with \node[align=center] {A \\ B \\ C}; (the align is needed to ensure that the `\\` are taken note of). – Loop Space Aug 18 '11 at 13:25
  • 3
    @Christian: Do you need a way of writing long strings of text that way, or would a "manual" approach like the one Andrew mentioned work for your application? – Jake Aug 18 '11 at 13:50
  • The strings are some characters long. Single words like entry, vip or staff. I'll try these days. Thanks – Christian Wolf Aug 18 '11 at 23:09
6

As I said in the comments, just about anything is allowed in a node; in particular, multi-line text. The only thing is that the node needs to know how to vertically align the text. This is controlled by the align key (Section 16.4.3 in the PGF manual (PGF2.10)). In the following, I've chosen center. Getting the size of the node after is simple using the anchors. To ensure that the anchors are big enough that the resulting shape will be clear of the text, I chose an ellipse as the node shape. As you say, it may not be worth designing a whole new shape just for one symbol, so I've drawn something vaguely like what you describe manually. In order to get the arc right, I wrote a little helper macro that measures the distance between two points. This is because arcs are specified using radii, but we want to draw an arc between certain points. So we measure the points first and use the measurements to specify the radii.

\documentclass[border=10]{standalone}
%\url{http://tex.stackexchange.com/q/26028/86}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\makeatletter
\newcommand{\measure}[2]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \pgf@xa=-\pgf@x\relax
  \pgf@ya=-\pgf@y\relax
  \tikz@scan@one@point\pgfutil@firstofone#2\relax
  \advance\pgf@x by \pgf@xa\relax
  \advance\pgf@y by \pgf@ya\relax
  \edef\xdistance{\the\pgf@x}%
  \edef\ydistance{\the\pgf@y}%
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node[align=center,ellipse] (a) {this\\is\\some\\text\\arranged\\vertically};
\measure{(a.west)}{(a.north)}
\draw (a.east) |- (a.north) -| (a.west) arc[x radius=\xdistance, y radius=\ydistance, start angle=-180, end angle=0];
\end{tikzpicture}
\end{document}

Result:

vertical text in a node

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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