[Tex/LaTex] Adding two labels to an edge in TikZ, close to the endpoints

tikz-pgf

I'm quite new to TikZ. I know how to make two nodes A and B, how to connect A and B by an edge with the draw command, and how to add a label to the edge. But now I want to add two labels: One close to the node A, and the other one close to the node B. What is the preferred way to do this? It would be nice to tell TikZ to place the label close to the endpoint (not colliding with the node), without giving the exact position.

Also, I would like edge-labels in a smaller font. Is there an easier way than adding some resizing command to each of the the labels?

This example illustrates what I want:

\begin{tikzpicture}[auto]
\node (A) at (0,0) {A};
\node (B) at (2,4) {B};
\draw (A) to node[align=center] {first line should be smaller and close to B\\second line should be smaller and close to A} (B);
\end{tikzpicture}

Best Answer

You can use near start and near end. I think this is what you're describing:

\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{pxfonts}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[auto]
\node (A) at (0,0) {A};
\node (B) at (2,4) {B};
\draw[font=\tiny] (A) to node[near end] {first line should be smaller and close to B} 
                         node[near start] {second line should be smaller and close to A} (B);
\end{tikzpicture}

\end{document}

enter image description here

To get even closer, you can use very near start.