[Tex/LaTex] Joining line segments in Tikz gives notched corners

tikz-pgf

I am new to using TikZ and have a very simple question that I can't find the answer to online. I am joining line segments in a tikzpicture, but the corner points seem to be missing yielding a notched appearance with thick lines (and when zooming in). A very short code segment is given below:

\begin{tikzpicture}[black,line width = 2pt,scale = 1.0]
\draw (0,0) -- (1,0);
\draw (1,0) -- (1,1);
\draw (1,1) -- (2,1);
\end{tikzpicture}

Because of the way I need to draw my figure I cannot join several points in a cycle. So I need some way of adding points to the 'notches' that gives sharp corners. It seems to me that I should be able to add small rectangular nodes, but I'm not sure of the exact syntax for that so the size of the nodes is the same width as the lines. Thank you for any advice.

Best Answer

Use the line cap option to specify how lines "end" (p.167, pgfmanual, v3.01a).

\documentclass[tikz,border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}[line width=2pt]
  \draw (0,0) -- (1,0);
  \draw (1,0) -- (1,1);
  \draw (1,1) -- (2,1);
  \node[right] at (2,.5) {line cap=butt (default)};
\end{tikzpicture}
\begin{tikzpicture}[line width=2pt,line cap=rect]
  \draw (0,0) -- (1,0);
  \draw (1,0) -- (1,1);
  \draw (1,1) -- (2,1);
  \node[right] at (2,.5) {line cap=rect};
\end{tikzpicture}
\begin{tikzpicture}[line width=2pt,line cap=round]
  \draw (0,0) -- (1,0);
  \draw (1,0) -- (1,1);
  \draw (1,1) -- (2,1);
  \node[right] at (2,.5) {line cap=round};
\end{tikzpicture}
\end{document}

enter image description here

enter image description here

enter image description here