Graphics, Figures & TablesTikz and how to create a node [near end]

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
LagrangeEU
Posts: 6
Joined: Wed May 11, 2011 7:53 pm

Tikz and how to create a node [near end]

Post by LagrangeEU »

Hello LC!

I am having a problem with TikZ and making it do what I want. In fact this is what made me sign up for this forum.
I am making a figure with TikZ and my problem is I want to use draw some line between to known points, say I know the coordinates. Somewhere along the line I would like to have some text "on" the line, but in such a way that the text does not go through the text. It might be best explained by the following code from the TikZ manual.

Code: Select all

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw (0,0) .. controls +(up:2cm) and +(left:3cm) .. (1,5)
node[at end] {|at end|}
node[very near end] {|very near end|}
node[near end] {|near end|}
node[midway] {|midway|}
node[near start] {|near start|}
node[very near start] {|very near start|}
node[at start] {|at start|};
\end{tikzpicture}
\end{document}
What I want is basically the above, but where the line treats it like (0,0) -- (very near start) -- (near start) -- etc (assuming that -- would draw the desired line and I had named the nodes accordingly). However it does not seem possible to simply name the nodes while using arguments as [midway], since it will not be positioned after the entire line is read, which means that the line has already been drawn where the node should go.

I hope my problem is clear and somebody can give me an idea to perfect my picture :D

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Tikz and how to create a node [near end]

Post by shadgrind »

I'm having a hard time trying to understand what exactly you're looking for. If you just want to get the coordinates of points along the path, you could draw the path white, name the coordinates at various points on the path, then use those coordinates later:

Code: Select all

\begin{tikzpicture}
\draw[white] (0,0) .. controls +(up:2cm) and +(left:3cm) .. (1,5)
node[very near end](A) {}
node[near start](B) {};
\draw (A) -- (B);
\end{tikzpicture}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Tikz and how to create a node [near end]

Post by cgnieder »

LagrangeEU wrote:[...] Somewhere along the line I would like to have some text "on" the line, but in such a way that the text does not go through the text. [...]
I assume you mean "that the line does not go through the text"? You could just fill the nodes with white in order to do that:

Code: Select all

\begin{tikzpicture}
 \draw (0,0) -- node[midway,fill=white]{midway} (5,0);
\end{tikzpicture}
LagrangeEU wrote:I hope my problem is clear [...]
Not exactly, I'm afraid...

Regards,
Clemens
site moderator & package author
LagrangeEU
Posts: 6
Joined: Wed May 11, 2011 7:53 pm

Tikz and how to create a node [near end]

Post by LagrangeEU »

Thank you guys! I think that cgneider's proposal is the most general one and will cover harder cases.

As I said my current problem is solved. To illustrate what I did see this example:

Code: Select all

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[white] (0,0) -- node[near end,black] (nearendnode) {Near End} (5,0);
\draw (0,0) -- (nearendnode) -- (5,0);
\end{tikzpicture}
\end{document}
The above could have been done by calculating the correct position of the node, but this might be very hard in general.

To answer my own question in general, it is just a matter of placing the things to draw in the right order

Code: Select all

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw (0,0) .. controls +(up:2cm) and +(left:3cm) .. (1,5)
node[near end,black,fill=white] (near)  {near end};
\draw[style=help lines] (-1.5,0) grid (2,6); 
\end{tikzpicture}
\end{document}
Thank you both, again!
Post Reply