5

What is necessary to "complete" the lines used to \draw complete shapes?

\documentclass{letter}
\usepackage{tikz}
\begin{document}

\tikzset{every picture/.style=thick}

\begin{tikzpicture}[scale=0.2]
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- (11,-1);

\draw(12,8) arc (-90:180:1);
\draw(12,8) -- (12,9) -- (11,9);
\end{tikzpicture}

\end{document}

The corners are jagged in some corners, or "pierce" the shape in other corners.

enter image description here

7

The rules are as follows:

  1. Use complete, single paths, or, using your own words from the comments below: "draw it in one shot". That is, do not use more than one \draw, \path or so command. Also make sure that there are no gaps.
  2. Add -- cycle to close a closed path.
  3. Optional: use an appropriate line join.

Applied to your picture, this yields

\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\tikzset{every picture/.style=thick}

\begin{tikzpicture}[scale=0.2]
\begin{scope}
 \draw  (12,4) -- (12,3) arc (-90:180:1) -- cycle;
 \draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope} 
\begin{scope}[xshift=3.5cm,line join=round]
 \draw  (12,4) -- (12,3) arc (-90:180:1) -- cycle;
 \draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope} 
\begin{scope}[xshift=7cm,line join=bevel]
 \draw  (12,4) -- (12,3) arc (-90:180:1) -- cycle;
 \draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope} 
\begin{scope}[xshift=10.5cm,miter limit=1]
 \draw  (12,4) -- (12,3) arc (-90:180:1) -- cycle;
 \draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope} 
\end{tikzpicture}
\end{document}

enter image description here

This surveys a few different line join options, see p. 172 of pgfmanual v3.1.4 for more information.

Of course, if you patch together different paths to have nice line joins, it may happen that you have to, or it is at least advantageous to, revert the direction of some segments. For instance, when patching together the three segments of the addendum of your question, I reverted one arc to get

\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\tikzset{every picture/.style=thick}
\begin{tikzpicture}[scale=0.25]
\draw (5,7) -- (7,5) -- (5,5) -- (7,7) 
arc (90:180:1) arc (0:90:1) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

The path can be shortened to

\draw (7,5) -- (5,5) -- (7,7) arc (90:180:1) arc (0:90:1) -- cycle; 
  • Just in case if rounded join is not wanted, would this approach still work? – SuperAl Dec 10 '19 at 1:01
  • @SuperAl Absolutely. You can either just drop line join=round, or replace it by line join=bevel or dial some miter limit, see p. 172 of pgfmanual v3.1.4. – Schrödinger's cat Dec 10 '19 at 1:03
  • Got it! Not to use disparate primitives, draw in one shot. – SuperAl Dec 10 '19 at 1:33
  • @SuperAl Precisely. And sometimes one may want to revert the direction of one, at least I found that this simplifies things when joining the additional diagram, please see the update. – Schrödinger's cat Dec 10 '19 at 1:34

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.