16
\begin{tikzpicture}[node distance=1.5cm]
 \node[state] (A) {A};
 \node[state] (C) [right of=A] {C};
 \node[state] (B) [below in the middle of=A and C] {B}
\end{tikzpicture}

Something like this:

 A C
 \/
 B 

I couldn't figure out how to do it. I believe there is Tree extension but I want to write the graph without using it.

  • 2
    Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. – Peter Grill Nov 9 '12 at 23:22
12
  1. First draw the node B. Then use above left and above right to draw the nodes A and B respectively. OR
  2. Use xshift and push the node B by half of the length between nodes. (You know the node distance). But in this method the minimum distance between the node A (or C) and node B is not 1.5cm but greater. OR
  3. First draw A and then B and then C.

And in cases 1 and 3 the nodes A and c are not separated by 1.5cm :-(.

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
 \node at (0,0) (B) {B};
 \node (C) [above right of=B] {C};
 \node (A) [above left of=B] {A};
\end{tikzpicture}
\begin{tikzpicture}[node distance=1.5cm]
 \node at (0,0) (A) {A};
 \node (C) [right of= A] {C};
 \node (B) [below of=A,xshift=.75cm] {B};
\end{tikzpicture}
\begin{tikzpicture}[node distance=1.5cm]
 \node at (0,0) (A) {A};
 \node (B) [below right of= A] {B};
 \node (B) [above right of=B] {C};
\end{tikzpicture}
\end{document}

enter image description here

19

You can use tikz's calc library to compute the mid point and place the node below that:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
 \node (A) {A};
 \node (C) [right of=A] {C};
 \coordinate (Middle) at ($(A)!0.5!(C)$);
 \node (B) [below of=Middle] {B};
\end{tikzpicture}
\end{document}
  • does not work for me... – Abramodj Mar 17 '13 at 14:31
  • @Abramodj: Saying it "does not work " does not provide any useful information with which anyone can provide you with any help. I'd suggest you post a new question and include a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. If your case does not even compile, then ensure that it compiles if that one line is commented. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Mar 17 '13 at 17:56
  • You are definitely right! I'm sorry, it was just a [ parenthesis that was no supposed to be there. My fault! – Abramodj Mar 17 '13 at 18:19
  • 1
    @Abramodj: No problem. Glad I could help. :-) Feel free to post a question should you get stuck in the future. I have myself posted several questions that turned out to be quite embarrassing, but sometimes it is difficult to see a problem, especially after you have been staring at it for a while... Often I discover the problem as I compose a MWE, but if not then I have something with which you can post a question. – Peter Grill Mar 17 '13 at 19:39
6

Here is a solution using pos=.5 to find the middle point of path A to C and positioning TikZ library to put the B node 1cm below this middle point:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
 \node (A) {A};
 \node (C) [right of=A] {C};
 \path (A) -- (C) node[pos=.5,below=1cm] (B) {B};
\end{tikzpicture}
\end{document}

enter image description here

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.