I would like to align the text a — b — c at the bottom and not at the top as it is now:
\documentclass{article}
\usepackage{pgfplots,tikz}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}
\node(a) {a};
\node[right=of a] (b) {b};
\node[right=of b] (c) {c};
\draw (a) -- (b) -- (c);
\end{tikzpicture}
\end{document}
Moreover, I would like to know: Do I have to place the tikzpicture always inside a "figure" environment? Because, if I do not, then it appears aligned with the rest of the text and not as "a picture".
Lastly, I would like to have small circles in the place of a, b, c in the tikzpicture above (and the names a,b,c above these circles), but when I do it, the connecting lines touch the circles, which I do not like. I would prefer the current format (where the line does not touch a, b and c but connects them) and have circles instead. How can I do it?
Since it is just a simple picture of a line connecting three points, I would like to keep the code as simple and basic as possible. Thanks.
Best Answer
In your original code, to align the nodes at the bottom, you can set the appropriate anchors, by saying
right=of a.south east,anchor=south west
, instead of justright=of a
. Depending on what you want, you might want to use thebase west
anchor instead ofsouth west
, but then you can usebase right=of
instead ofright=of
, as shown in the code below.You do get problems with drawing the lines, as they appear to be drawn between the
east
andwest
anchors, and since these are at different vertical positions, the lines are tilted a bit. There are probably several methods for fixing that, the one shown below is like this:The construct
(<coord 1> |- <coord 2>)
is a coordinate specification (see section 13.3.1, Intersections of perpendicular lines, in the manual). It is the point that has the x-coordinate of<coord 1>
, and the y-coordinate of<coord 2>
. Think of|-
as two lines, one going vertically from the first point, one horizontally from the second, and the coordinate is at the intersection of those. Similarly, with-|
you get the y-coordinate of the first point, and the x-coordinate of the second.Note further that if you do
\draw (a) -- (b) (c) -- (d);
then you will not get a line betweenb
andc
, because there is no--
between the coordinates.Finally, I show a method for having circles with letters above. If you don't require the vertical alignment at the baseline, you can remove the
[anchor=base,label distance=1mm]
from thecirc
style.Addendum --
mid
After glancing at the manual I realized that the
mid east
/mid west
anchors can be used here along withbase right
for slightly shorter code, at least for the present case. Themid
anchors are defined to be 0.5ex above the baseline.