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'd like to use xypic to draw a Hasse diagram similar to this one:

enter image description here

which was generated with the following code:

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
\[
\xymatrix{
s_{2,0} \ar@{-}[d] \ar@{-}[drrr] & &
s_{2,1} \ar@{-}[dl] \ar@{-}[dr] & &
s_{2,2} \ar@{-}[dlll] \ar@{-}[d] \\
s_{1,0} \ar@{-}[drr] &
s_{1,1} \ar@{-}[dr] &&
s_{1,2} \ar@{-}[dl] &
s_{1,3} \ar@{-}[dll] \\
& & s_{0} & & }
\]
\end{document}

The only problem is that there's too much space between the second and third entries of the second row. I'm using five columns, obviously, because I have an odd number of entries on the first and third rows. Is there any way to close that gap? In the diagram above, it isn't a big deal, but that diagram was just my first attempt at getting the code right. Here's the actual diagram:

enter image description here

Yikes! It doesn't even fit on the page! (That's the page border on the right, as shown in my PDF viewer.) It was generated using the same code as the above, except with an extra command to generate the ordered triples.

Here's an example of the kind of thing I'm looking to do:

enter image description here

Note the equal space between the four entries of the second row. This diagram is from a great discussion on using TikZ to draw Hasse diagrams, but I'd prefer to use xypic. For some reason, TikZ doesn't want to cooperate with my installation. I tried to make my diagram with the following code, using the TikZ example as a model:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.7]
\node (20) at (-3,2) {$s_{2,0}$};
\node (21) at (0,2)  {$s_{2,1}$};
\node (20) at (3,2)  {$s_{2,2}$};
\node (10) at (-3,0) {$s_{1,0}$};
\node (11) at (-1,0) {$s_{1,1}$};
\node (12) at (1,0)  {$s_{1,2}$};
\node (13) at (3,0)  {$s_{1,3}$};
\node (00) at (0,-2) {$s_{0}$};
\draw (00) -- (10) -- (20) -- (12) -- (00) --(11) -- (22) -- (13) --(00);
\draw (10) -- (21) -- (13);
\end{tikzpicture}
\end{document}

But no luck when compiling:

! Undefined control sequence.
l.1837 \pgfdeclareplotmark
                          {ball}

Perhaps the LaTeX installation on my ancient OpenBSD server is out of date, but upgrading it is a daunting proposition, so I'd prefer to use xypic if possible.

share|improve this question
    
Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. –  Henri Menke Jun 19 '13 at 14:48
    
I'll make the changes; thanks for the suggestion. –  Kellvyn Jun 19 '13 at 15:03
add comment

1 Answer

up vote 5 down vote accepted

It is not clear that you should use \xymatrix for this. I'll start with a discussion of options available with that, correct your tikz code and then show how the tikz code can be implemented in xy.

In \xymatrix you set the column spacing with the @C= directive and specify a dimension, such as 1em. To have a chance of equal spacing you want equal numbers of columns for corresponding entries. A start is:

Sample output

\documentclass{article}
\usepackage[all]{xy}
\begin{document}
\[
\xymatrix@C=0em{
s_{2,0} \ar@{-}[d] \ar@{-}[drrrr] &&&
s_{2,1} \ar@{-}[dlll] \ar@{-}[drrr] &&&
s_{2,2} \ar@{-}[dllll] \ar@{-}[d] \\
s_{1,0} \ar@{-}[drrr] &&
s_{1,1} \ar@{-}[dr] &&
s_{1,2} \ar@{-}[dl] &&
s_{1,3} \ar@{-}[dlll] \\
&&& s_{0} &&& }
\]
\end{document}

Now there is a version @!C= that forces equal spacing, but in this case makes the diagram a lot wider. You can use @C= with negative dimensions to squeeze things more, but using negative dimensions in the version @!C= does something unexpected.

In your intended example you should perhaps consider ways of making the nodes narrower, e.g. by stacking the node material vertically, using something like

\txt{\( s_{1,0} \)\\\( \scriptstyle\langle\{\varphi_3\},\{\varphi_4\}\rangle \)}

Your tikz code has only one compilation problem, the node (22) is incorrectly named:

tikz sample

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.7]
\node (20) at (-3,2) {$s_{2,0}$};
\node (21) at (0,2)  {$s_{2,1}$};
\node (22) at (3,2)  {$s_{2,2}$}; %Corrected node name
\node (10) at (-3,0) {$s_{1,0}$};
\node (11) at (-1,0) {$s_{1,1}$};
\node (12) at (1,0)  {$s_{1,2}$};
\node (13) at (3,0)  {$s_{1,3}$};
\node (00) at (0,-2) {$s_{0}$};
\draw (00) -- (10) -- (20) -- (12) -- (00) --(11) -- (22) -- (13) --(00);
\draw (10) -- (21) -- (13);
\end{tikzpicture}
\end{document}

Now in xy you can make similar constructions.

Sample xy output

\documentclass{article}
\usepackage[all]{xy}
\begin{xy}
0;<0.5cm,0pt>:
(-3,2)*{s_{2,0}}="20";
(0,2)*{s_{2,1}}="21";
(3,2)*{s_{2,2}}="22";
(-3,0)*{s_{1,0}}="10";
(-1,0)*{s_{1,1}}="11";
(1,0)*{s_{1,2}}="12";
(3,0)*{s_{1,3}}="13";
(0,-2)*{s_{0}}="00";
"10" **\dir{-};
"20" **\dir{-};
"12" **\dir{-};
"00" **\dir{-};
"11" **\dir{-};
"22" **\dir{-};
"13" **\dir{-};
"00" **\dir{-};
"10";
"21" **\dir{-};
"13" **\dir{-};
\end{xy}
\end{document}

You use xy rather than xymatrix. Then the coordinate system is set up on the first line with origin at 0 and x-unit vector at (0.5cm,0).

After that you can place material at points by specifying coordinates as (x,y) and dropping the material via *{material}. The position is named by adding a final ="name".

Once the points have been named you can connect them. You note the start position with "name"; and then connect a second point to this with "name2" **\dir{-}; to produce straight lines. Now "name2" is your last position and you can connect it to "name3" by just adding a similar construct. In the above code "00" is already the last mentioned coordinate, so we don't need to repeat it and the start of the connecting process.

You should refer to the full xy reference manual texdoc xyref for further details to improve spacing etc. You will see there that you can write the shorter @{-} instead of \dir{-} for these particular edges.

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.