2

I'm drawing a multi-segment line with TikZ as below:

\begin{figure*}
\center
\begin{tikzpicture}
    \draw[->] (0.25,0) --(0.75,1.2) -- (1.25,1.5) -- (1.75,0.7) -- (2.25,1.1) -- (2.75,0.5) -- (3.25,1.5) -- (4.25,1.8);
\end{tikzpicture}
\end{figure*}

I'd like a few of the segments of the line to be thick, and the rest to be thin. Or, put another way, I'd like the line to be thick from (0.25,0) up until (1.75,0.7).

If I just do \draw[thick] ... the whole line becomes thick, which is not what I want.

Any thoughts?

Thanks!

4
  • This isn't possible without splitting the path into segments, or doing something a little fancy. See tex.stackexchange.com/q/43309/86 for one way to do this. Is that close to what you want? Apr 11, 2012 at 16:27
  • That looks pretty good, but I couldn't get it working, and it's unclear if you can mix to[] blocks with -- connections.
    – Richard
    Apr 11, 2012 at 16:46
  • @AndrewStacey, I've commented on the answer you linked to above - the code there doesn't seem to be working.
    – Richard
    Apr 11, 2012 at 16:49
  • 1
    There was a spurious blank line. I've removed it. Apr 11, 2012 at 17:51

2 Answers 2

7

The solution is somewhere on the site but about dashed line and solid line. I can't find this answer but I will delete my answer if someone gives the good link

\documentclass{minimal}
\usepackage{tikz} 

\tikzset{%
xultra thick/.style={to path={%
\pgfextra{%
 \draw[line cap=round, line join=round,ultra thick]
      (\tikztostart) -- (\tikztotarget);} (\tikztotarget) \tikztonodes}},
xthin/.style={to path={%
\pgfextra{%
 \draw[line cap=round, line join=round,thin] 
       (\tikztostart) -- (\tikztotarget);} (\tikztotarget)  \tikztonodes}}} 
\begin{document}
\begin{tikzpicture}
  \draw (0.25,0) -- (0.75,1.2) -- (1.25,1.5) 
  to[xultra thick]  (1.75,0.7) -- (2.25,1.1) -- (2.75,0.5)
                 -- (3.25,1.5) to[xthin] (4.25,1.8);
\end{tikzpicture}
\end{document} 

enter image description here

2
1

In a very basic way you can break the segment into two subsegments:

\begin{tikzpicture}
\draw[thick] (0.25,0) --(0.75,1.2) -- (1.25,1.5) -- (1.75,0.7); 
\draw[->] (1.75,0.7) -- (2.25,1.1) -- (2.75,0.5) -- (3.25,1.5) -- (4.25,1.8);
\end{tikzpicture}

Another solution that allows you to decide the thickness of the line is:

 \begin{tikzpicture}
 \draw[line width=1pt] (0.25,0) --(0.75,1.2) -- (1.25,1.5) -- (1.75,0.7); 
 \draw[->,line width=0.5pt](1.75,0.7) -- (2.25,1.1) -- (2.75,0.5) -- (3.25,1.5) -- (4.25,1.8);
 \end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .