我有一张 TikZ 生成的图片,但无法添加一些细节。
我的例子:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\wireheight{2} % height of one segment
\newcommand\wirewidth{1} % width of a segment
\newcommand\wiredist{0.5} % distance between wires
\pgfmathsetmacro\pairdist{2*(\wirewidth+\wiredist)} % distance between pairs of wires
% \wire[options]{name}{start}{height}{width}
\newcommand\wire[5][]%
{\draw[#1]
(#3) coordinate (#2-0)
-- ++(0,#4) coordinate (#2-1)
-- ++(#5,0) coordinate (#2-2)
-- ++(0,#4) coordinate (#2-3)
-- ++(-#5,0) coordinate (#2-4)
-- ++(0,#4) coordinate (#2-5)
-- ++(#5,0) coordinate (#2-6)
-- ++(0,0.5*#4) coordinate (#2-7);
}
\begin{document}
\begin{tikzpicture}[rounded corners,>=stealth, shorten >=1pt, shorten <=1pt]
\foreach \i in {0,...,2}
{\wire[thick,red]{B-\i}{\i*\pairdist,0}{\wireheight}{\wirewidth}
\wire[thick,blue]{G-\i}{{(\i+1)*\pairdist-\wiredist},0}{\wireheight}{-\wirewidth}
}
\draw[<->] ($(G-0-3)!-0.5!(G-0-3)$) -- +(-0.5,0) node[above]{$\kappa_{1}$};
\draw[<->] ($(B-1-4)!0.25!(B-1-5)$) -- +(-0.5,0) node[above]{$\kappa_{2}$};
\end{tikzpicture}
\end{document}
我无法在开头添加蓝色线并在结尾添加红色线。另外,我希望在上方两根线的中间添加 $\kappa_{1}$ 和 $\kappa_{2}$ <-->。该怎么做?
答案1
左边一条蓝线,右边一条红线很容易,只需交换\foreach
draw
命令里的颜色即可。
第二个问题关于 kappa 标签对我来说不清楚,所以这只是一个猜测。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\wireheight{2} % height of one segment
\newcommand\wirewidth{1} % width of a segment
\newcommand\wiredist{0.5} % distance between wires
\pgfmathsetmacro\pairdist{2*(\wirewidth+\wiredist)} % distance between pairs of wires
% \wire[options]{name}{start}{height}{width}
\newcommand\wire[5][]%
{\draw[#1]
(#3) coordinate (#2-0)
-- ++(0,#4) coordinate (#2-1)
-- ++(#5,0) coordinate (#2-2)
-- ++(0,#4) coordinate (#2-3)
-- ++(-#5,0) coordinate (#2-4)
-- ++(0,#4) coordinate (#2-5)
-- ++(#5,0) coordinate (#2-6)
-- ++(0,0.5*#4) coordinate (#2-7);
}
\begin{document}
\begin{tikzpicture}[rounded corners,>=stealth, shorten >=1pt, shorten <=1pt]
\foreach \i in {0,...,2}
{
\wire[thick,blue]{G-\i}{{(\i)*\pairdist-\wiredist},0}{\wireheight}{-\wirewidth}
\wire[thick,red]{B-\i}{\i*\pairdist,0}{\wireheight}{\wirewidth}
}
\draw[<->] ($(G-1-2)!-0.5!(G-2-3)$) -- +(-0.5,0) node[midway,above]{$\kappa_{1}$};
\draw[<->] ($(B-0-3)!-0.5!(B-0-4)$) -- +(-0.5,0) node[midway, above]{$\kappa_{2}$};
\end{tikzpicture}
\end{document}