我调整了一些代码,但现在我到达了边界。我想将以下形状旋转 90 度,以便它之后看起来向上。
但我的问题是将连接线也从西向北放置。似乎这个形状没有我需要的锚点。我的代码:
\documentclass{article}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usepackage{circuitikz}
\newcommand{\mysize}{2.5cm}
\newcommand{\connectlength}{0.6cm}
\tikzstyle{mynode}=[draw, minimum size=\mysize,
label={[anchor = east]25:$\text{A}$},
label={[anchor = east]-25:$\text{B}$},]
\tikzstyle{mynodemirror} = [draw, minimum size=\mysize,
label={[anchor = west]155:$\text{A}$},
label={[anchor = west]205:$\text{B}$},]
\tikzstyle{mynodebelow} = [draw, minimum size=\mysize,
label={[anchor = north]110:$\text{A}$},
label={[anchor = north]70:$\text{B}$}]
\begin{document}
\begin{tikzpicture}[]
% Hilfslinien
% \draw[help lines] (0,-7) grid (7,7);
\node[mynode] (master) {node 0};
\node[mynodemirror, right=8cm of master] (slave1) {node 1};
\node[mynodebelow, below left=2.0cm of slave1] (slave2) {node 2};
% \node[vcc, above=2cm of slave1] (nodevcc) {VCC};
\draw ($(master.north east)!.5!(master.east)$) to[short,-o] ++(\connectlength,0) coordinate (oben_master);
\draw ($(master.south east)!.5!(master.east)$) to[short,-o] ++(\connectlength,0) coordinate (unten_master);
\draw ($(slave1.north west)!.5!(slave1.west)$) to[short,-o] ++(-\connectlength,0) coordinate (oben_slave1);
\draw ($(slave1.south west)!.5!(slave1.west)$) to[short,-o] ++(-\connectlength,0) coordinate (unten_slave1);
% how to change the following line to make the connections look upwards?
\draw ($(slave2.north west)!.5!(slave2.west)$) to[short,-o] ++(-\connectlength,0) coordinate (oben_slave2);
\draw ($(slave2.south west)!.5!(slave2.west)$) to[short,-o] ++(-\connectlength,0) coordinate (unten_slave2);
\draw (oben_master) to[short] (oben_slave1);
\draw (unten_master) to[short](unten_slave1);
\end{tikzpicture}
\end{document}
结果是:
我尝试修复node 2
-shape(但无法编译)
\documentclass{article}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usepackage{circuitikz}
\newcommand{\mysize}{2.5cm}
\newcommand{\connectlength}{0.6cm}
\tikzstyle{mynode}=[draw, minimum size=\mysize,
label={[anchor = east]25:$\text{A}$},
label={[anchor = east]-25:$\text{B}$},]
\tikzstyle{mynodemirror} = [draw, minimum size=\mysize,
label={[anchor = west]155:$\text{A}$},
label={[anchor = west]205:$\text{B}$},]
\tikzstyle{mynodebelow} = [draw, minimum size=\mysize,
label={[anchor = north]110:$\text{A}$},
label={[anchor = north]70:$\text{B}$}]
\begin{document}
\begin{tikzpicture}[]
% Hilfslinien
% \draw[help lines] (0,-7) grid (7,7);
\node[mynode] (master) {node 0};
\node[mynodemirror, right=8cm of master] (slave1) {node 1};
\node[mynodebelow, below left=2.0cm of slave1] (slave2) {node 2};
% \node[vcc, above=2cm of slave1] (nodevcc) {VCC};
\draw ($(master.north east)!.5!(master.east)$) to[short,-o] ++(\connectlength,0) coordinate (oben_master);
\draw ($(master.south east)!.5!(master.east)$) to[short,-o] ++(\connectlength,0) coordinate (unten_master);
\draw ($(slave1.north west)!.5!(slave1.west)$) to[short,-o] ++(-\connectlength,0) coordinate (oben_slave1);
\draw ($(slave1.south west)!.5!(slave1.west)$) to[short,-o] ++(-\connectlength,0) coordinate (unten_slave1);
% how to change the following line to make the connections look upwards?
\draw ($(slave2.west north)!.5!(slave2.north)$) to[short,-o] ++(-\connectlength,0) coordinate (oben_slave2);
\draw ($(slave2.east north)!.5!(slave2.north)$) to[short,-o] ++(-\connectlength,0) coordinate (unten_slave2);
\draw (oben_master) to[short] (oben_slave1);
\draw (unten_master) to[short](unten_slave1);
\end{tikzpicture}
\end{document}
我希望你能理解我的问题。
非常感谢。
答案1
首先,没有锚点west north
或east north
。其次,连接的线路必须向上,所以应该是++(0,\connectlength)
。
我也将to[...]
其改为--
,因为直线--
更适合。箭头尖端的选项可以设为\draw[-o] ...
。
我还添加了从到和slave2
之间的线。这里生成一个实心圆作为箭头尖端,并使线稍长一些,以便圆位于水平线上而不是水平线下方(该值是通过反复试验确定的)。注释给出了从 到 的线垂直于 的线上的点(参见 PGF 手册版本 3.0.1a 的第 13.5.5 节)。master
slave1
-Circle
shorten >=1.8pt
($(B)!(A)!(C)$)
(B) -- (C)
(A)
(B) -- (C)
所有这些导致:
代码:
\documentclass{article}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
%\usepackage{flowchart}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usepackage{circuitikz}
\newcommand{\mysize}{2.5cm}
\newcommand{\connectlength}{0.6cm}
\tikzstyle{mynode}=[draw, minimum size=\mysize,
label={[anchor = east]25:$\text{A}$},
label={[anchor = east]-25:$\text{B}$},]
\tikzstyle{mynodemirror} = [draw, minimum size=\mysize,
label={[anchor = west]155:$\text{A}$},
label={[anchor = west]205:$\text{B}$},]
% adapted angles here
\tikzstyle{mynodebelow} = [draw, minimum size=\mysize,
label={[anchor = north]117:$\text{A}$},
label={[anchor = north]63:$\text{B}$}]
\begin{document}
\begin{tikzpicture}[]
% Hilfslinien
% \draw[help lines] (0,-7) grid (7,7);
\node[mynode] (master) {node 0};
\node[mynodemirror, right=8cm of master] (slave1) {node 1};
\node[mynodebelow, below left=2.0cm of slave1] (slave2) {node 2};
% \node[vcc, above=2cm of slave1] (nodevcc) {VCC};
\draw[-o] ($(master.north east)!.5!(master.east)$) -- ++(\connectlength,0) coordinate (oben_master);
\draw[-o] ($(master.south east)!.5!(master.east)$) -- ++(\connectlength,0) coordinate (unten_master);
\draw[-o] ($(slave1.north west)!.5!(slave1.west)$) -- ++(-\connectlength,0) coordinate (oben_slave1);
\draw[-o] ($(slave1.south west)!.5!(slave1.west)$) -- ++(-\connectlength,0) coordinate (unten_slave1);
\draw[-o] ($(slave2.north west)!.5!(slave2.north)$) -- ++(0,\connectlength) coordinate (oben_slave2);
\draw[-o] ($(slave2.north east)!.5!(slave2.north)$) -- ++(0,\connectlength) coordinate (unten_slave2);
\draw (oben_master) -- (oben_slave1);
\draw (unten_master) -- (unten_slave1);
\draw[-Circle,shorten >=-1.8pt] (oben_slave2) -- ($(oben_master)!(oben_slave2)!(oben_slave1)$);
\draw[-Circle,shorten >=-1.8pt] (unten_slave2) -- ($(unten_master)!(unten_slave2)!(unten_slave1)$);
\end{tikzpicture}
\end{document}
答案2
使用小图片pic
代码绘制图片很简单:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows}
\tikzset{
base/.style = {draw, minimum size=22mm},
xs/.style = {xshift=#1mm},
ys/.style = {yshift=#1mm},
NR/.pic = {\node (@nr) [base] {#1};
\draw[-o] ([ys=+3] @nr.east) node[left] {A}
-- ++ (4mm,0) coordinate (-A);
\draw[-o] ([ys=-3] @nr.east) node[left] {B}
-- ++ (4mm,0) coordinate (-B);
},
NL/.pic = {\node (@nr) [base] {#1};
\draw[-o] ([ys=+3] @nr.west) node[right] {A}
-- ++ (-4mm,0) coordinate (-A);
\draw[-o] ([ys=-3] @nr.west) node[right] {B}
-- ++ (-4mm,0) coordinate (-B);
},
NA/.pic = {\node (@nr) [base] {#1};
\draw[-o] ([xs=-3] @nr.north) node[below] {A}
-- ++ (0,4mm) coordinate (-A);
\draw[-o] ([xs=+3] @nr.north) node[below] {B}
-- ++ (0,4mm) coordinate (-B);
}
}
\begin{document}
\begin{tikzpicture}
\pic (n1) {NR=node 0};
\pic (n2) at (6, 0) {NL=node 0};
\pic (n3) at (3,-4) {NA=node 0};
\draw (n1-A) -- (n2-A);
\draw (n1-B) -- (n2-B);
%
\draw[fill] (n3-A) -- (n1-A -| n3-A) circle (1pt);
\draw[fill] (n3-B) -- (n1-B -| n3-B) circle (1pt);
\end{tikzpicture}
\end{document}