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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a very basic square:

  A \ar[r] \ar[d] & B \ar[d] \\
  C \ar[r] & D

What is the easiest way to place the text "hi" in the center of the square?

share|improve this question
Welcome to TeX.SX. In this group we love minimal working examples so we can try out your code immediately, without having to wonder about the required packages or having to type in the rest of your document. Providing a minimal example also shows that you've done some basic research. – Marc van Dongen Feb 28 '12 at 4:24
For more information on minimal working examples, see meta.tex.stackexchange.com/questions/228/… – qubyte Feb 28 '12 at 4:33

I recommend a TikZ solution. Specifying the diagram is a bit more work than using xypic but relative positioning is easier.




\draw node[matrix,row sep=2em,column sep=2em] (my matrix) {
   \node(A){$A$}; & \node(B){$B$}; \\
   \node(C){$C$}; & \node(D){$D$}; \\
}; % <-----
\draw (my matrix) node {hi};
\foreach \source/\destination in {A/B,A/C,B/D,C/D} {
    \draw[->] (\source) -- (\destination);


Since you want to draw hi in the centre of the matrix, you could have also written node {hi}' before the semicolon with the<-----and remove\drawcommand that draws thehi` node. I think the code is a bit clearer the way I presented it.

share|improve this answer
  A \ar[r] \ar[d] \ar@{}[dr]|{\mbox{Hi}}
  & B \ar[d] \\
  C \ar[r] & D

That adds in an invisible arrow (the @{} makes it invisible) going diagonally from the upper left to the lower right corner, and "breaks" the arrow with an \mbox containint the word "Hi".

share|improve this answer
Nice trick. How would you put the word at the position that is on the vertical line halfway between A and B, and the horizontal line that is twice as far from C as it is from A? – Marc van Dongen Feb 28 '12 at 7:49
@MarcvanDongen -- this is cheating, and requires some guesstimating: replace the \mbox{Hi} by \mathstrut\raisebox{1.5ex}{Hi}. the strut is needed to establish a baseline, otherwise the box will be treated as an operator and vertically centered. – barbara beeton Feb 28 '12 at 14:04
@barbarabeeton Thanks. The question was asked to show that you (probably) needed some form of cheating to do this with xypic. – Marc van Dongen Feb 28 '12 at 14:08
@MarcvanDongen I'm confused by your question, since the line between A and B is horizontal, and the one between A and C is vertical. Anyway, you can drop the word anywhere at all using, e.g.,\ar@{}[]+<2em,0ex>\txt{Hi} to drop it 2em to the right of the current node. (That draws an invisible arrow to the point and then drops a text object at the end of the arrow.) See, e.g., "Getting up and running with AMS-LaTeX", page 36, at the end of section 8, from your favorite CTAN mirror. – Phil Hirschhorn Feb 29 '12 at 5:58

Your Answer


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.