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'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}
share|improve this question
2  
Could you please provide a minimal example document? –  Jake Apr 10 '13 at 18:25
    
You can try node [xshift=...,yshift=...] ... . But I agree with Jake you must provide a minimal working example (MWE) –  karathan Apr 10 '13 at 18:31
    
You can use the styles at start, very near start, near start, midway, near end, very near end and at end which translate to the positions 0, 0.125, 0.25, 0.5, 0.75, 0.875 and 1. You can also place labels at the start and end nodes, where you can define a label distance. — You can use the font key for font switching macros. –  Qrrbrbirlbel Apr 10 '13 at 18:33
    
@Jake: I've added an example. Is this ok? –  azimut Apr 10 '13 at 18:39
    
@Qrrbrbirlbel: Thanks! Now I know how to create two labels with near start and near end. Where exactly should I use the font keyword? –  azimut Apr 10 '13 at 19:07
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
    
Thanks. Just playing with the remarks in Qrrbrbirlbel's comment, I figured that I can add two nodes to the same \draw command. However, I'm still not sure where to put the font keyword. –  azimut Apr 10 '13 at 19:05
    
@azimut (and kmachinnis): Define a style, say mini, or use every node, that contains font=\tiny, and then you can say (on one path): \draw[every node/.append style={font=\tiny}] (A) -- node[very near start] {…} node[very near end] {…} (B);. Of course, you can also say node [font=\tiny, very near start] …. –  Qrrbrbirlbel Apr 10 '13 at 19:07
    
Thanks-- is there an advantage to having mini as a style rather than \tiny in the node itself? –  kmacinnis Apr 10 '13 at 19:14
1  
Why not : \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);? –  Alain Matthes Apr 10 '13 at 19:21
1  
@AlainMatthes Ah, I never know which node options can be assigned to paths and scopes and which need explicitly assigned to every node or a style. –  Qrrbrbirlbel Apr 10 '13 at 19:23
show 1 more comment

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.