4

I would like to label coordinates as such. For example, I want to put the text "(1,0)" next to the coordinate point (1,0). I've been looking at the nodes documentation - is there a better way to do it? Here is the figure I have drawn, for reference.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz} 
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (8,8);
\draw (0,0) -- (8,8);
\draw (0,2) -- (6,8); % line from (0,1/4) to (3/4,1)
\draw[->] (0,0) -- (8.5,0) node[anchor=north west] {$v_1$};
\draw[->] (0,0) -- (0,8.5) node[anchor=south east] {$v_2$};
\fill[black!40!white] (0,2) -- (6,8) -- (0,8) -- cycle;
\addplot[mark=*] coordinates {(0,1)} node:{$(0,1)$}{}; 

\end{tikzpicture}
\end{document}
2
  • Hi, welcome. The last line of your tikzpicture cannot work, \addplot is defined by pgfplots (which you don't load), and only works inside an axis environment (which you don't have, or seem to need). And the : after node shouldn't be there. Do you just want \node[below] at (1,0) {$(1,0)$};. Commented Apr 12, 2017 at 21:05
  • Yes, sorry, that was my first attempt. It wasn't working, hence my problem! THanks.
    – TCW
    Commented Apr 12, 2017 at 21:07

1 Answer 1

3

If I understood you correctly, than you looking for something like this:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (8,8);
\draw (0,0) -- (8,8);
\draw (0,2) -- (6,8); % line from (0,1/4) to (3/4,1)
\draw[->] (0,0) -- (8.5,0) node[anchor=north west] {$v_1$};
\draw[->] (0,0) -- (0,8.5) node[anchor=south east] {$v_2$};
\fill[black!40!white] (0,2) -- (6,8) -- (0,8) -- cycle;
\node[circle,inner sep=1pt,fill=red,label=left:{$(0,1)$}] at (0,1) {};% this replace your `addplot`
\end{tikzpicture}
\end{document}

Note: addplot is pgfplots macro and cannot be used in a tikzpicture unless you don't include it in a axis environment (your MWE can not be compiled).

If you like to labeled some other coordinates, the possible solution is for example:

\coordinate[label=left:{(0,2)}] (A) at (0,2);
\coordinate[label=above:{(6,8)}] (B) at (6,8);
\draw[fill=black!40!white] (A) -- (B) -| (A);

by which you can replace:

\draw (0,2) -- (6,8); % line from (0,1/4) to (3/4,1)
\fill[black!40!white] (0,2) -- (6,8) -- (0,8) -- cycle;

in your MWE. Another alternative can be, for example:

\draw (0,2) node[left] {(0,1)} -- (6,8) node[above] {(6,8)}; % line from (0,1/4) to (3/4,1)

etc.

1
  • @CarLaTeX, done.
    – Zarko
    Commented Apr 13, 2017 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .