8

Questions:

  1. Why are the top corners of this number line missing?
  2. Why aren't the bottom corners or any other corners of this number line missing?
  3. How do I ensure the corners are always there?
\documentclass{article}

\usepackage[left=1.5cm,right=1.5cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}


\begin{document}

\begin{tikzpicture}[line width=0.08cm]

\draw (0,0)--(5,0);
\draw (0,0.3)--(5,0.3);

\foreach \x in {0,...,5}
 {
 \node at (\x,-0.55) {\x};
 \draw (\x,-0.3)--(\x,0.3);
 }

\foreach \x in {0,...,5}
 \draw (\x,0)--(\x,0.3);

\end{tikzpicture}

\end{document}

That code yields this:

enter image description here

1 Answers1

9

The problem here is that the lines end at a certain point – exactly at this point. have a look at this image (MWE below):

first image

The black dot marks (0,0). Both lines are drawn to (0,0) and because of the heavy line width it seems that the corner between them is missing, while actually the lines are exactly as specified: ending in (0,0).

However there are some ways to get a corner:

  1. make one path going through (0,0) having a real corner there
  2. use line cap = rect to add a little extra bit at the end of each line, so the overlap of the red an blue line form a corner (affects both ends!).
  3. lengthen the path by half the amount of the line width with shorten < = 0.5\pgflinewidth (affects only the end specified by using either shorten < = start or shorten > = end)

1 to 3 from left to right:

alternatives

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[line width = 4mm]
   \draw [red] (0,-2) -- (0,0);
   \draw [blue] (2,0) -- (0,0);
   \fill (0,0) circle [radius = 1pt];
   \begin{scope}[xshift=25mm]% solution 1
      \draw [red] (0,-2) -- (0,0) -- (2,0);
      \fill (0,0) circle [radius = 1pt];
   \end{scope}
   \begin{scope}[xshift=50mm]% solution 2
      \draw [red,  line cap=rect] (0,-2) -- (0,0);
      \draw [blue] (2,0) -- (0,0);
      \fill (0,0) circle [radius = 1pt];
   \end{scope}
   \begin{scope}[xshift=75mm]% solution 3
   \draw [red, shorten > = -0.5\pgflinewidth] (0,-2) -- (0,0);
   \draw [blue] (2,0) -- (0,0);
   \fill (0,0) circle [radius = 1pt];
   \end{scope}
\end{tikzpicture}
\end{document}

For your code I’d use version 1 and add little vertical pieces to the horizontal line:

result

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[line width=0.08cm]
\draw (0,0) -- (5,0);
\draw (0,0.2) -- (0,0.3) -- (5,0.3) -- (5,0.2);
\foreach \x in {0,...,5}
 {
  \node at (\x,-0.55) {\x};
  \draw (\x,-0.3)--(\x,0.3);
 }
\foreach \x in {0,...,5}
 \draw (\x,0)--(\x,0.3);
\end{tikzpicture}
\end{document}
Tobi
  • 56,353