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've got this Tikz picture and I'd like to increase the horizontal distance between the nodes while keeping the vertical distance unchanged. I know how to do it by placing the nodes manually using coordinates, but I'd rather not do it if it can be avoided.

picture showing the nodes

Here's the code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  [align=center,node distance=2cm]
  \node[label=above:A] (A)                      
       {(1)};
  \node[label=above:B1] (B1) [above right of=A]
       {($m+1$)};
  \node[label=above:B2] (B2) [below right of=A]
       {($m+1$)};
  \node[label=above:C] (C)  [below right of=B1]
       {($2m-1$)};
\end{tikzpicture}
\end{document}

Any help appreciated.

share|improve this question
    
Instead of specifying coordinates you could use xshift=<length> to indicate the amount of the shift. –  Peter Grill Apr 8 '12 at 22:39
    
@PeterGrill: nice suggestion. –  Ernest A Apr 8 '12 at 22:50
2  
you can also specify below(or above) and right (or left) dimensions separately like above right=0.7cm and 1cm of A. You have to use \usetikzlibrary{positioning} for this. –  Harish Kumar Apr 8 '12 at 23:13
    
@HarishKumar: this could be a solution. –  Ernest A Apr 8 '12 at 23:47

3 Answers 3

up vote 15 down vote accepted

You can specify the relative x and y positions separately using the tikz library positioning

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  [align=center,node distance=2cm]  %< no need of this global node separation
  \node[label=above:A] (A)                      
       {(1)};
  \node[label=above:B1] (B1) [above right=0.7cm and 4cm of A]
       {($m+1$)};
  \node[label=above:B2] (B2) [below right=0.7cm and 4cm of A]
       {($m+1$)};
  \node[label=above:C] (C)  [below right=0.7cm and 4cm of B1]
       {($2m-1$)};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
1  
What is the default distance? –  StrawberryFieldsForever Aug 2 '13 at 4:04

The first method uses positioning and node distance=2cm and 4cm] but I don't appreciate it.

/tikz/node distance=⟨shifting part⟩ (no default, initially 1cm and 1cm) The value of this key is used as ⟨shifting part⟩ is used if and only if a ⟨of-part⟩ is present, but no ⟨shifting part⟩.

and

When the ⟨shifting part⟩ is of the form ⟨number or dimension⟩ and ⟨number or dimension⟩, it has (essentially) the effect of shifting the node vertically upwards by the first ⟨number or dimension⟩ and to the left by the second.

I think it's strange to shift first vertically and I prefer to make a shift manually by myself.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  [align=center,node distance=2cm and 4cm] 
  \node[label=above:A]  (A)                        {(1)};
  \node[label=above:B1] (B1) [above right= of A]   {($m+1$)};
  \node[label=above:B2] (B2) [below right= of A]   {($m+1$)};
  \node[label=above:C]  (C)  [below right= of B1]  {($2m-1$)};
\end{tikzpicture}
\end{document} 

I prefer +(2, 2) and ++(2, 2) it's like above right and it's more flexible. But It's fine to have a lot of possibilities !!!

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [align=center]
  \path  (0, 0)   node[label=above:A]   (A)  {(1)}
        +(2, 2)   node[label=above:B1]  (B1) {($m+1$)}
       ++(2,-2)   node[label=above:B2]  (B2) {($m+1$)}
       ++(2, 2)   node[label=above:C]   (C)  {($2m-1$)};
\end{tikzpicture} 

\begin{tikzpicture} [align=center,xscale=2]  % or x=2cm
  \path  (0, 0)   node[label=above:A]   (A)  {(1)}
        +(2, 2)   node[label=above:B1]  (B1) {($m+1$)}
       ++(2,-2)   node[label=above:B2]  (B2) {($m+1$)}
       ++(2, 2)   node[label=above:C]   (C)  {($2m-1$)};
\end{tikzpicture} 

\end{document} 

enter image description here

share|improve this answer

As Harish mentioned, you can use the positioning library and adjust horizontal and vertical position.

Another way, allowing you to specify distances for horizontal and vertical distances, is to use matrices. With this you can set the row and column distances. The code, for you diagram, is

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}[align=center]

\matrix[matrix of nodes,row sep=0.5cm,column sep=2cm]{
&|[label=above:B1]| ($m+1$)&\\
|[label=above:A]| (1)&&|[label=above:C]| ($2m-1$)\\
&|[label=above:B2]| ($m+1$)&\\
};

\end{tikzpicture}

\end{document}

The result is

enter image description here

share|improve this answer

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.