This question is sequel to this question

Dash pattern that starts with space

enter image description here

The idea is how to draw a vector that is, say 50% full line and 50% dashed line. percusse suggested this solution

\begin{tikzpicture}[mydashed/.style={dashed,dash phase=3pt}]
\draw[very thin] (0,-1) -- (0,1);
\draw[ultra thick] (-2,0) -- (0,0);
\draw[ultra thick,mydashed,->] (0,0) -- (2,0);

but he also mentioned that "to draw the combined vector in one go, one can use a decoration". I have read manual and find no answer how to do that. Can someone show me how to do that?

Dashed part must start with white part.


You can start with next code. Using show path construction decoration was stolen from Mark Wibrow's answer to Complicated tikz vector diagram (Approximate Miss Distance Produced by Turns)

I hope you'll improve how line width and arrow are set in decoration.

\documentclass[tikz, border=5]{standalone}
  half dashed/.style={
    decoration={show path construction, 
      lineto code={
          \draw[#1] (\tikzinputsegmentfirst) --($(\tikzinputsegmentfirst)!.5!(\tikzinputsegmentlast)$);,
          \draw[dashed, dash phase=3pt,->,#1] ($(\tikzinputsegmentfirst)!.5!(\tikzinputsegmentlast)$)--(\tikzinputsegmentlast);,


\draw (0,0) rectangle (2,2);
\draw (2,0) rectangle (4,2);

\draw [half dashed={very thin}] (0,1)--(4,1);
\draw [half dashed={ultra thick}] (0,1.5)--(4,1.5);
\draw [half dashed={line width=1mm}] (0,0.5)--(4,0.5);


enter image description here


On https://tex.stackexchange.com/users/3235/percusse's suggestion I made up this low-level solution:


\state{initial}[width=0.5*\pgfdecoratedpathlength,next state=final]{%

\draw[ultra thick,dashed,dash phase=3pt,decorate,decoration=halffull,->] (-2,0) -- (2,0);
\draw[very thin] (0,-1) -- (0,1);


enter image description here

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.