对于仅一个的十字相乘法,得到解决方案如下:
\begin{tikzpicture}
\node (a) at (0,0);
\node (b) at (2,0);
\node (c) at (2,1);
\node (d) at (0,1);
\draw[-] (a) [red]-- (c);
\draw[-] (b) [blue]-- (d);
\draw (a) node [left] {$x+y$};
\draw (b) node [right] {$2$};
\draw (c) node [right] {$4$};
\draw (d) node [left] {$x-3y$};
\end{tikzpicture}
但对于两个十字相乘问题,开始想到如下方法:
\begin{tikzpicture}
\node (A) at (0,1);
\node (B) at (2,1);
\node (C) at (4,1);
\node (D) at (0,0);
\node (E) at (2,0);
\node (F) at (4,0);
\draw (A) node [left] {$2x$};
\draw (B) node {$-3y$};
\draw (C) node [right] {$z$};
\draw (D) node [left] {$3x$};
\draw (E) node {$y$};
\draw (F) node [right] {$-2z$};
\draw [-] (A.east) -- (E.west);
\draw [-] (D.east) -- (B.west);
\draw [-] (B.east) -- (F.west);
\draw [-] (E.east) -- (C.west);
\draw [-] (A.east) [dashed]-- (F.west);
\draw [-] (D.east) [dashed]-- (C.west);
\end{tikzpicture}
但是效果不好。
这后,想到拆成两个组合,勉强可以使用:
\begin{tikzpicture}
\node (a) at (0,0);
\node (b) at (2,0);
\node (c) at (2,1);
\node (d) at (0,1);
\draw[-] (a) [red]-- (c);
\draw[-] (b) [blue]-- (d);
\draw (a) node [left] {$3x$};
\draw (b) node [right] {$-2y$};
\draw (c) node [right] {$-3y$};
\draw (d) node [left] {$2x$};
\node (e) at (3,0);
\node (f) at (5,0);
\node (g) at (5,1);
\node (h) at (3,1);
\draw[-] (e) [red]-- (g);
\draw[-] (h) [blue]-- (f);
\draw (f) node [right] {$5$};
\draw (g) node [right] {$4$};
\draw [-] (a.east) [dashed]-- (g.west);
\draw [-] (d.east) [dashed]-- (f.west);
\end{tikzpicture}
但感觉方法不好。大家有没有好的建议?
多谢。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (A) at (0, 1.5) {$ 2x $};
\node (B) at (0, 0) {$ 3x $};
\node (C) at (3, 1.5) {$ -3y $};
\node (D) at (3, 0) {$ -2y $};
\node (E) at (6, 1.5) {$ 4 $};
\node (F) at (6, 0) {$ 5 $};
\draw (A.east) -- (D.west);
\draw[dashed] (A.east) -- (F.west);
\draw (B.east) -- (C.west);
\draw[dashed] (B.east) -- (E.west);
\draw (C.east) -- (F.west);
\draw (D.east) -- (E.west);
\end{tikzpicture}
\end{document}
node
可以直接写文字.
方法很多,
\makebox[2em][c]{$xxx$}
作为 node
的文字内容,这样需要对齐的节点的宽度就是一致的了,只要内容自然宽度不超过给定的宽度;[every node./style={minimum size=7mm}]
之类的设置全局设定好 node
的最小宽度,当然,内容自然宽度超过这个数值的 node
其宽度还是自然宽度;[minimum size =7mm]
。也可以试试matrix
库:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes, column sep=15mm, row sep=8mm, inner sep=0.0mm,]
{
$2x$ & $-3y$ & $4$ \\
$3x$ & $-2y$ & $5$ \\
};
\draw[blue] (m-1-1) -- (m-2-2);
\draw[blue] (m-1-2) -- (m-2-3);
\draw[red ] (m-2-1) -- (m-1-2);
\draw[red ] (m-2-2) -- (m-1-3);
\draw[dashed] (m-1-1) -- (m-2-3);
\draw[dashed] (m-2-1) -- (m-1-3);
\end{tikzpicture}
\end{document}
这个代码有个问题,如果中间两项长度不一致,生成的线,会有出入,例如:
我用了一变通的方法,强制加了一个间隔:但效果似乎还是不尽人意。
@u934 我不了解你的具体需求是什么, 我用幻影简单做了一下