2

I am trying to find a better way to add a letter above each point on a simple single axis. I got the result I needed using this:

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-8,-1) rectangle (5.5,2);
\draw[<->,color=black] (-5.4,0.) -- (5.4,0.);
\foreach \x in {-5,-4,-3,-2,-1,0,1,2,3,4,5}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[color=black] (-5,.4) node {$A$};
\draw[color=black] (-4,.4) node {$B$};
\draw[color=black] (-3,.4) node {$C$};
\draw[color=black] (-2,.4) node {$D$};
\draw[color=black] (-1,.4) node {$E$};
\draw[color=black] (0,.4) node {$F$};
\draw[color=black] (1,.4) node {$G$};
\draw[color=black] (2,.4) node {$H$};
\draw[color=black] (3,.4) node {$I$};
\draw[color=black] (4,.4) node {$J$};
\draw[color=black] (5,.4) node {$K$};
\end{tikzpicture}

but I have to imagine there is a less "brute-forcey" way to do it. Any suggestions? (P.S. I am very new at this).

1

you give up on half of way ... you should exploit introduced loop:

\documentclass[tikz,
               border=3mm,
               ]{standalone}

\begin{document}
    \begin{tikzpicture}
% axis
\draw[<->] (-5.4,0.) -- (5.4,0.);
% ticks with labels
\foreach \x [count=\xx from -5] in {A,B,...,K}
    \draw (\xx,1mm) node[above] {$\x$}
                    -- + (0,-2mm)
                    node[below,font=\footnotesize] { $\xx$};
    \end{tikzpicture}
\end{document}

enter image description here

  • Perfect! I figured there had to be a way to use the loop, but I wasn't really sure how to introduce another variable to get both the numbering and the letters in there. Thank you! – Riley Jul 30 '17 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.