2

I have the following picture in TikZ at the moment:

\documentclass[11pt,a4paper]{report}      
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[>=angle 90]
\matrix(a)[matrix of math nodes,
row sep=3em, column sep=2.5em,
text height=1.5ex, text depth=0.25ex]
{X & H& X  \\
A&X &B \\
X & H' &X  \\};


\path[->,font=\scriptsize]
(a-1-2)  edge node[above]{$$} (a-2-3);

\path[->,font=\scriptsize]
(a-2-1)  edge node[above]{$$} (a-1-2);

\path[->,font=\scriptsize]
(a-2-1)  edge node[above]{$$} (a-3-2);

\path[->,font=\scriptsize]
(a-3-2)  edge node[above]{$$} (a-2-3);

\end{tikzpicture}
\end{document}

I was wondering if there is a way for me to get rid on the labels X on the nodes but still keep the nodes, so that I can draw the diamond. If I just leave it empty it gives an error saying that all nodes must be labelled, possibly empty. Is there some empty command?

  • Please begin your MWE with \document class, used libraries, \begin{document} and end{document}. As far I see, your example has some errors, for example list of nodes are ended with \} ... – Zarko Jun 12 '14 at 11:45
  • 1
    You could just substitute your "X" by "~" (a small space). – Clément Jun 12 '14 at 11:54
3

The question is unclear. You ask about removing X in the matrix? You can do it without problems:

\begin{tikzpicture}[>=angle 90]
\matrix(a)[matrix of math nodes,
  row sep=3em, column sep=2.5em,
  text height=1.5ex, text depth=0.25ex]
{   & H  &   \\   % <--- See? no X here
  A &    & B \\
    & H' &   \\};

\path[->,font=\scriptsize]
(a-1-2)  edge node[above]{$$} (a-2-3);

\path[->,font=\scriptsize]
(a-2-1)  edge node[above]{$$} (a-1-2);

\path[->,font=\scriptsize]
(a-2-1)  edge node[above]{$$} (a-3-2);

\path[->,font=\scriptsize]
(a-3-2)  edge node[above]{$$} (a-2-3);

\end{tikzpicture}

This code compiles without problem, and gives:

Result

Which apparently is what you wanted.

However you mention an error about "all nodes must be labelled, possibly empty". This error is not produced by the above code. You get this error, however, if you remove the {$$} in the nodes you put when drawing the edges.

Perhaps you got this error in previous iterations of your code, and then you incorrectly identified the source of the error.

Anyway, if you put a node object inside a path, like you did in the last part, you have to give it a content, which is the {$$} you put here. Apparently you don't want to give any content, because $$ produces no output after all. Then, why do you include those nodes?

You can perfectly draw an edge without introducing any node in the process. Simply:

\path[->,font=\scriptsize] (a-1-2)  edge (a-2-3);
\path[->,font=\scriptsize] (a-2-1)  edge (a-1-2);
\path[->,font=\scriptsize] (a-2-1)  edge (a-3-2);
\path[->,font=\scriptsize] (a-3-2)  edge (a-2-3);

This code is still weird, since you are using a font option, when you are not writing any text. I suspect that you removed too much from your "MWE", and thus is difficult to guess what you really needed. In order to draw the edges, a simpler syntax can be used:

\draw[->] (a-1-2) -- (a-2-3);
\draw[->] (a-2-1) -- (a-1-2);
\draw[->] (a-2-1) -- (a-3-2);
\draw[->] (a-3-2) -- (a-2-3);

Another possible source of problems is if you want to draw some edges from/to the empty nodes of the matrix. For example, this will fail:

\draw[->] (a-1-1) -- (a-2-2);

because when you leave an empty cell in the matrix, no node is created for that position, and thus the names (a-1-1) and (a-2-2) do not exist.

This problem can be solved by adding the option nodes in empty cells to the matrix. This way tikz creates invisible nodes for the cells which have no content, and you get also valid names for those cells.

\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\begin{tikzpicture}[>=angle 90]
\matrix(a)[matrix of math nodes, nodes in empty cells,
row sep=3em, column sep=2.5em,
text height=1.5ex, text depth=0.25ex]
{   & H  &   \\
  A &    & B \\
    & H' &   \\};

\draw[->] (a-1-2) -- (a-2-3);
\draw[->] (a-2-1) -- (a-1-2);
\draw[->] (a-2-1) -- (a-3-2);
\draw[->] (a-3-2) -- (a-2-3);
\draw[->] (a-2-1) -- (a-2-2);

\end{tikzpicture}

Result

1

Just leave them out? This works for me?

enter image description here

\documentclass[11pt,a4paper]{report}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[>=angle 90]
\matrix(a)[matrix of math nodes,
row sep=3em, column sep=2.5em,
text height=1.5ex, text depth=0.25ex]
{ & H   \\
 A&   &B\\
  & H'  \\};   
\path[->,font=\scriptsize](a-1-2)  edge node[above]{$$} (a-2-3);
\path[->,font=\scriptsize](a-2-1)  edge node[above]{$$} (a-1-2);   
\path[->,font=\scriptsize](a-2-1)  edge node[above]{$$} (a-3-2);   
\path[->,font=\scriptsize](a-3-2)  edge node[above]{$$} (a-2-3);

\end{tikzpicture}
\end{document}
  • The same result you can achieve without nodes in paths and definition of font size used in them. Also library decorations.pathmorphing is not necessary. – Zarko Jun 12 '14 at 12:45
  • @Zarko Presumably the OP wants the decorations in the their "real" example:) Note sure about the nodes, however, the $$ really should be giving an error as its jumping into display math mode, but I thought it compiled... – Andrew Jun 12 '14 at 12:50

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.