2

The following code

\documentclass[11pt]{article}
 \usepackage{amsmath}
 \usepackage{amsfonts}
 \usepackage{amssymb}
 \usepackage{amsthm}
 \usepackage[english, greek]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage{kmath, kerkis}
 \usepackage{pgf, tikz}
 \usetikzlibrary{arrows}
 \usepackage{caption}
 \usepackage{float}

  %custom commands 

  \newcommand{\A}{{\rm A}}
  \newcommand{\B}{{\rm B}}
 \begin{document}
 \begin{figure}[H]
 \centering
\begin{tikzpicture}[scale=0.7]
\draw [->, thick] (-2, 0) -- (6, 0);
\draw (6, 0) node[below]{$x$};
\draw [->, thick] (-1, -1) -- (2, 5);
\draw (2, 5) node[above]{$y$};
\draw (-0.7, 0) node[above]{${\rm O}$};
\draw [shift={(-0.5,0)},color=black,fill=black] (0,0) -- (0:0.6) arc (0:63.43:0.6) -- cycle;
\draw (0.3, 0.3) node[above]{$\theta$};
\foreach \i in {2, 3, 4}
{\draw [fill=black] (\i, \i) circle(2pt);   }  
\draw (2, 2) node[above]{$\A$};
\draw (3, 3) node[above]{$\B$};
\draw (4, 4) node[above]{$\Gamma$};
\draw (2, 2) -- (4, 4); 
\end{tikzpicture}
\captionsetup{labelformat=empty}
\caption{Σχήμα 16 } \label{fig16}
\end{figure}
\end{document}

enter image description here

As you can see from the code I have used \foreach to draw three circles. How can I do the same ( using \foreach ) to place the nodes A, B, Γ as seen in the picture? In this particular case there are only three points so I did it manually. What about if had 10 or more?

4
  • Does it have to be a gamma or could it be C?
    – TeXnician
    Commented Oct 28, 2017 at 7:45
  • Whatever you like. This is just a sample.. In the end , if need arise, I can adjust the text ... !! :)
    – Tolaso
    Commented Oct 28, 2017 at 7:46
  • @TeXnician Updated the preamble. Forgot the custom commands!
    – Tolaso
    Commented Oct 28, 2017 at 7:48
  • Didn't need those ;) You can work with standard LaTeX.
    – TeXnician
    Commented Oct 28, 2017 at 7:49

2 Answers 2

6

You can use a counter and then convert it to a letter using \Alph.

letters

\documentclass[11pt]{article}
 \usepackage{amsmath}
 \usepackage{amsfonts}
 \usepackage{amssymb}
 \usepackage{amsthm}
 \usepackage[english, greek]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage{kmath, kerkis}
 \usepackage{pgf, tikz}
 \usetikzlibrary{arrows}
 \usepackage{caption}
 \usepackage{float}

 \newcounter{ccount}

 \begin{document}
 \begin{figure}[H]
 \centering
\begin{tikzpicture}[scale=0.7]
\draw [->, thick] (-2, 0) -- (6, 0);
\draw (6, 0) node[below]{$x$};
\draw [->, thick] (-1, -1) -- (2, 5);
\draw (2, 5) node[above]{$y$};
\draw (-0.7, 0) node[above]{$\mathrm{O}$};
\draw [shift={(-0.5,0)},color=black,fill=black] (0,0) -- (0:0.6) arc (0:63.43:0.6) -- cycle;
\draw (0.3, 0.3) node[above]{$\theta$};
\foreach \i in {2, 3, 4}
{
      \setcounter{ccount}{\i}
      \addtocounter{ccount}{-1}
    \draw [fill=black] (\i, \i) circle(2pt) node[above] {\Alph{ccount}};
}
\draw (2, 2) -- (4, 4); 
\end{tikzpicture}
\captionsetup{labelformat=empty}
\caption{Σχήμα 16 } \label{fig16}
\end{figure}
\end{document}
7
  • Thank you! This is just great and simplifies my code .. !
    – Tolaso
    Commented Oct 28, 2017 at 7:51
  • @CarLaTeX As this is not really essential I didn't even notice ;) Thanks.
    – TeXnician
    Commented Oct 28, 2017 at 8:32
  • Instead of defining a counter it is easier to use count in the \foreach statement: \foreach \i [count=\cc] in {2,3,4} {...}. Probably it is better in this case to invert this and loop over the labels: \foreach \lab [count=\i from 2] in {A,B,C} {\draw [fill=black] (\i, \i) circle(2pt) node[above] {\lab};}
    – user30471
    Commented Oct 28, 2017 at 8:47
  • @Andrew I've tested your version and the count thing does not work (it's not a counter one could use with \Alph).
    – TeXnician
    Commented Oct 28, 2017 at 9:03
  • That's why I also suggested the second variation -- otherwise you can use \@Alph but you need to enclose in \makeatletter...\makeatother.
    – user30471
    Commented Oct 28, 2017 at 9:11
7

You can use a \foreach with two variables (see p.903, pgfmanual v3.0.1a):

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[english, greek]{babel}
\usepackage[utf8]{inputenc}
\usepackage{kmath, kerkis}
\usepackage{pgf, tikz}
\usetikzlibrary{arrows}
\usepackage{caption}
\usepackage{float}

\newcommand{\A}{\mathrm{A}}% \rm deprecated for 25 years
\newcommand{\B}{\mathrm{B}}

\begin{document}
\begin{figure}[H]
  \centering
  \begin{tikzpicture}[scale=0.7]
    \draw [->, thick] (-2, 0) -- (6, 0);
    \draw (6, 0) node[below]{$x$};
    \draw [->, thick] (-1, -1) -- (2, 5);
    \draw (2, 5) node[above]{$y$};
    \draw (-0.7, 0) node[above]{$\mathrm{O}$};
    \draw [shift={(-0.5,0)},color=black,fill=black] (0,0) -- (0:0.6) arc (0:63.43:0.6) -- cycle;
    \draw (0.3, 0.3) node[above]{$\theta$};
    \foreach \i/\letter in {2/\A, 3/\B, 4/\Gamma}{
      \draw [fill=black] (\i, \i) circle(2pt) node[above]{$\letter$};
    }  
    \draw (2, 2) -- (4, 4); 
  \end{tikzpicture}
  \captionsetup{labelformat=empty}
  \caption{Σχήμα 16} \label{fig16}
\end{figure}
\end{document}
1
  • I accepted the other answer because it automates the process and I'll be needing it for the other figure I have to draw !!
    – Tolaso
    Commented Oct 28, 2017 at 12:43

You must log in to answer this question.

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