# Straight line in TikZ with 'continued' marking in the middle

I'm looking to get a line drawn in a way that I've often seen in schematics: ---||---, so a line, interrupted by two vertical bars (like a capacitor sign), the two vertical bars very close by, also slightly slanted to the right. Similarly, the same for an upward line. I have been looking through the tikz manual but I'm at loss how to do this. I tried the midway node decoration, but then I don't know how to get the paralle lines that break the path (and are slanted) - \| is not want I need.

(The goal is to simulate that things (boxes) to the left of the line are repeated several times along this path).

Thank you!

Here's another option using decorations to produce the two requested styles:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\def\MarkLt{6pt}
\def\MarkSep{3pt}

\tikzset{
TwoMarks/.style={
postaction={decorate,
decoration={
markings,
mark=at position #1 with
{
\begin{scope}[xslant=0.2]
\draw[line width=\MarkSep,white,-] (0pt,-\MarkLt) -- (0pt,\MarkLt) ;
\draw[-] (-0.5*\MarkSep,-\MarkLt) -- (-0.5*\MarkSep,\MarkLt) ;
\draw[-] (0.5*\MarkSep,-\MarkLt) -- (0.5*\MarkSep,\MarkLt) ;
\end{scope}
}
}
}
},
TwoMarks/.default={0.5},
OneMark/.style={
postaction={decorate,
decoration={
markings,
mark=at position #1 with
{
\draw[-] (0,-\MarkLt) -- (0,\MarkLt) ;
}
}
}
},
OneMark/.default={0.5}
}

\begin{document}

\begin{tikzpicture}[>=latex]
\draw[TwoMarks,->] (0,0) -- (0,2);
\draw[TwoMarks] (0,0) -- (2,0);
\draw[TwoMarks,->] (0,0) -- (2,2);
\draw[OneMark,<-] (2,0) -- (2,2);
\draw[OneMark] (0,2) -- (2,2);

\draw[TwoMarks=0.25,->] (3,2) -- ++(2,0);
\draw[TwoMarks,->] (3,1) -- ++(2,0);
\draw[TwoMarks=0.75,->] (3,0) -- ++(2,0);

\draw[OneMark=0.25,->] (6,2) -- ++(2,0);
\draw[OneMark,->] (6,1) -- ++(2,0);
\draw[OneMark=0.75,->] (6,0) -- ++(2,0);
\end{tikzpicture}

\end{document}


# Features:

• Using \MarkLt and \MarkSep one chan change the line length and separation between lines for the double mark.

• By default, the decorations are placed in the middle of the path, but using TwoMarks=<value> or OneMark=<value>, the position can be changed.

• Thank you! I'm not very familiar with decorations and styles and ... tikz in general.... If I choose in the application of the decoration an arrow-style, then the two slanted lines also get arrow heads. How would I turn these off? – osdf Aug 20 '15 at 16:08
• @osdf You're welcome! Please see my updated answer. – Gonzalo Medina Aug 20 '15 at 16:15
• @osdf I updated my answer introducing some improvements and new functionality. I thought this new version might be of interest for you. – Gonzalo Medina Aug 20 '15 at 18:03
• Thanks!! I fiddled around with such a paramterization, too, but yours is so much better :). – osdf Aug 20 '15 at 20:51

A sloped node could be used with white background and the symbol as contents you want to use:

\documentclass{article}
\usepackage{tikz}

\tikzstyle{cont} = [
sloped,
node contents={//},
fill=white,
inner xsep=.1em,
inner ysep=0pt,
]

\begin{document}
\begin{tikzpicture}
\draw
(0, 0) -- node[pos=.5, cont] {} (2, 2)
(0, 0) -- node[pos=.5, cont] {} ++(2, 0)
-- node[pos=.5, cont] {} ++(0, 2)
-- node[pos=.5, cont] {} ++(-2, 0)
-- node[pos=.5, cont] cycle
;
\end{tikzpicture}
\end{document}


The result, that also shows the white background of the continuation nodes:

• My fairly recent TexLive (Ubuntu 14.04) does not know the key 'node content'. Is there an alternative approach? – osdf Aug 20 '15 at 14:18
• @osdf Then you have probably TikZ < v3.0. You can then remove the key and add // to the empty braces: \node[...] {//}. – Heiko Oberdiek Aug 20 '15 at 14:37
• Since pos is always 0.5, perhaps a decoration could be more appropriate here? – Gonzalo Medina Aug 20 '15 at 14:46
• @Heiko Thanks, that works. In the schema drawings, the line goes till the slanted symbol. If I understand your approach right, this is not possible here? – osdf Aug 20 '15 at 14:46
• @GonzaloMedina It's just a simple example, the position depends on the wishes of the OP. Otherwise, it could be added to the style. – Heiko Oberdiek Aug 20 '15 at 14:48

A simple solution with @HeikoOberdiek's idea in mind:

\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[par/.style={sloped,fill=white,inner sep=-.6ex}]
\draw (0, 0) -- node[par]{//} (2, 2)
(0, 0) -- node[par]{//} ++(2, 0)
-- node[sloped]{\textbar} ++(0, 2)
-- node[sloped]{\textbar} ++(-2, 0)
-- node[par]{//} cycle;
\end{tikzpicture}

\end{document}


• Thanks! Did not think about negative inner seps, only tried 0. – osdf Aug 20 '15 at 16:07