Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Reading "tikz Multi-segment Line of Varying Thickness" provides a good explanation to join segments, but it seems that the rounded corner transition is the only way to do this nicely?

I would like to join segments of different thickness with a nice sharp miter, getting similar results in the case of these two:

Lines of the same thickness have a nice miter:

\draw [very thick] (0.45,-0.2) to (0.45,0.17) to (0.75,-0.17) to (0.75,0.2);

But if I try to join a thick line to a thin line, there is an artifact:

\draw [very thick] (1.3,0.2) to (1,0) to (1.3,-0.2);
\draw (1,0) to (1.3,-0.2) to (1.3,0.2) to (1,0);    

nice miter same thickness, but nasty joints between two

The resulting mitre would appear thus (except not edited by hand):

desired mitre

share|improve this question
    
Welcome to TeX.SE. –  Peter Grill Feb 3 at 3:58
add comment

3 Answers

up vote 15 down vote accepted

This is a work around using \clip.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \clip (1.3,0.2) -- (1,0) -- (1.3,-0.2) -- (1.3,0.2) -- cycle;
  \draw [line width=2pt] (1.3,0.2) to (1,0) to (1.3,-0.2);
  \draw (1.3,-0.2) to (1.3,0.2);
\end{tikzpicture}
\end{document}

enter image description here

Note that a line width of 2pt will give a resultant line width of 1pt as the other part is clipped off. So you have to adjust properly.

If this forms a part of bigger diagram, the \clipping part may be enclosed in a scope so as to limit the clipping:

\begin{scope}
   \clip (1.3,0.2) -- (1,0) -- (1.3,-0.2) -- (1.3,0.2) -- cycle;
   \draw [line width=2pt] (1.3,0.2) to (1,0) to (1.3,-0.2);
   \draw (1.3,-0.2) to (1.3,0.2);
\end{scope}
share|improve this answer
1  
This seems to be the correct solution. –  Alain Matthes Feb 3 at 9:13
    
This is much simpler than any workaround I would have come up with (in a reasonable time frame). Too bad this result has to be rent by brute force. –  repurposer Feb 4 at 2:45
    
It might be good to mention the clip command affects any code coming after as well. Wrapping the snippet in \begin{scope}...\end{scope} seems to keep things contained. –  repurposer Feb 4 at 3:13
    
@repurposer: It is evident. I wasn't aware of the entire picture you are trying to draw. I have added the details. Thanks. –  Harish Kumar Feb 4 at 4:25
add comment

I would recommend you use line cap=round along with line join=round, and a slight xshift to connect these. Here is a before and after comparison:

enter image description here

References:

Notes:

  • Also in the original version, you were not just drawing a thin line, you were actually drawing over the thick lines as can be seen by using the color red option to the very thick line:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw [very thick] (1.3,0.2) to (1,0) to (1.3,-0.2);
\draw (1,0) to (1.3,-0.2) to (1.3,0.2) to (1,0);  

\begin{scope}[xshift=0.5cm, draw=blue]
\draw [line cap=round, line join=round, very thick] (1.3,0.2) -- (1,0) -- (1.3,-0.2);
\draw [line cap=round, shift={(0.1ex,0)}] (1.3,-0.2) to (1.3,0.2);  
\end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Indeed, I was drawing over the very thick lines, i guess that could be removed from the example. Except the attempt was, to force the miter joiner. In this case, my preferred result would be to have sharp corners. Rounded joints do not suit the stylistic requirements of the graphic. –  repurposer Feb 3 at 3:27
    
@repurposer: If you don't want to use round corners, how do you suggest that a very thick line and a thin have a corner? The only option I can think of is to have a curved line (with minimal curvature) as the thin line so that it can go out and come in at an angle. Would that be an option? –  Peter Grill Feb 3 at 3:31
    
see updated post -- the idea would be to extrapolate the edges of the line segments such that they intersect (as is done with same-sized segments), and preventing the 'thickness' of the line to cause it to bulge out beyond the outer edge of the other –  repurposer Feb 3 at 3:41
    
@repurposer: Oh, I see. I can only think of a manual way to do that, which would not be useful if you need to do this often. Sorry, I was not able to be of more help. Oppsss, did not realize you were a new user... –  Peter Grill Feb 3 at 3:58
    
And thanks, @Peter Grill. I think, in this case a manual solution would be ok because I will only use it once or twice tonight -- but, useful things are useful. –  repurposer Feb 3 at 4:07
add comment

Rather more of this had to be done by eye than I would have liked, but nevertheless this is possible with the arrow heads defined at TikZ: changing colour of a path half way along (see my third (!) answer there (chronologically) and Qrrbrbirlbel's).

\documentclass{article}
%\url{http://tex.stackexchange.com/q/157254/86}

\usepackage{tikz}

\makeatletter

\pgfkeys{
  /tikz/sharp arrow angle/.code={%
    \pgfsetarrowoptions{sharp left}{#1}
    \pgfsetarrowoptions{sharp right}{#1}
  },
  /tikz/sharp left arrow angle/.code={%
    \pgfsetarrowoptions{sharp left}{#1}
  },
  /tikz/sharp right arrow angle/.code={%
    \pgfsetarrowoptions{sharp right}{#1}
  }
}

\tikzset{sharp arrow angle=30}

\pgfarrowsdeclare{sharp left}{sharp left}{%
  \pgfmathsetlength{\pgf@xa}{.5*\pgflinewidth * tan(\pgfgetarrowoptions{sharp left})}
  \pgfarrowsleftextend{\pgf@xa}
  \pgfarrowsrightextend{\pgf@xa}
}{%
  \pgfmathsetlength{\pgf@xa}{\pgflinewidth * tan(\pgfgetarrowoptions{sharp left})}
  \pgfpathmoveto{\pgfqpoint{-.1\pgflinewidth}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{0pt}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgf@xa}{.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{-.1\pgflinewidth}{.5\pgflinewidth}}
  \pgfusepathqfill
}
\pgfarrowsdeclare{sharp right}{sharp right}{%
  \pgfmathsetlength{\pgf@xa}{.5*\pgflinewidth * tan(\pgfgetarrowoptions{sharp right})}
  \pgfarrowsleftextend{\pgf@xa}
  \pgfarrowsrightextend{\pgf@xa}
}{%
  \pgfmathsetlength{\pgf@xa}{\pgflinewidth * tan(\pgfgetarrowoptions{sharp right})}
  \pgfpathmoveto{\pgfqpoint{-.1\pgflinewidth}{.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{0pt}{.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{\pgf@xa}{-.5\pgflinewidth}}
  \pgfpathlineto{\pgfqpoint{-.1\pgflinewidth}{-.5\pgflinewidth}}
  \pgfusepathqfill
}

\makeatother

\begin{document}
\begin{tikzpicture}[scale=20]
\pgfmathsetmacro\ang{90 - atan2(.3,.2)}
\draw [line width=2cm,sharp arrow angle=\ang,sharp left-sharp right] (1.3,0.2) to (1,0) to (1.3,-0.2);
\draw [blue,line width=1cm,sharp arrow angle=\ang,sharp left-sharp right] (1.3,-0.2603) to (1.3,0.2603);
\end{tikzpicture}
\end{document}

mitred corners via arrows

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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