我能够完成代码,但我想知道是否有更快或更有效的方法来创建它。
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{soul}
\usepackage{ragged2e}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage{tikz,pgfplots,quotes}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=newest}
\newcommand*{\myprime}{^{\prime}\mkern-1.2mu}
\newcommand*{\dprime}{^{\prime\prime}\mkern-1.2mu}
\newcommand*{\trprime}{^{\prime\prime\prime}\mkern-1.2mu}
\newcommand\df[4]{\(\displaystyle\int_{#1}^{#2}#3,d#4=\)}
\newcommand\ex[1]{\textbf{Example #1:}}
\newcommand\indef[2]{\(\displaystyle\int{#1}d{#2}=\)}
\begin{document}
\begin{tikzpicture}
\node (a) at (-3,0) {\(u(x)\)};
\node (b) at (-3,-1){\(u^{\myprime}(x)\)};
\node (c) at (-3,-2){\(u^{\dprime}(x)\)};
\node (d) at (-3,-3){\(u^{\trprime}(x)\)};
\node (e) at (-3,-4){\(u^{iv}(x)\)};
\node (f) at (3,0) {\(v(x)\)};
\node (g) at (3,-1.5) {\(v^{\myprime}(x)\)};
\node (h) at (3,-2.5) {\(v^{\dprime}(x)\)};
\node (i) at (3,-3.5) {\(v^{\trprime}(x)\)};
\node (j) at (3,-4.5) {\(v^{iv}(x)\)};
\draw[latex-latex] node[below]{\(+\)}(a)--(g);
\draw[latex-latex] (b)--(h)node[midway,above]{\(-\)};
\draw[latex-latex](c)--(i)node[midway,above]{\(+\)};
\draw[latex-latex](d)--(j) node[midway,above]{\(-\)};
\end{tikzpicture}
\end{document}
答案1
以下是几种方法。
使用tikz-cd
:
\documentclass[12pt,a4paper]{article}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz, diagrams={>={latex}}}
\begin{document}
\begin{tikzcd}[column sep=4cm, row sep=.5cm]
u\arrow[dr, <->, "+"] & v\\
u'\arrow[dr, <->, "-"] & v'\\
u''\arrow[dr, <->, "+"] & v''\\
u'''\arrow[dr, <->, "-"] & v'''\\
u^{iv} & v^{iv}
\end{tikzcd}
\end{document}
使用positioning
:
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance=.5cm and 5cm]
\node(u0){$u$};
\node[below=of u0](u1){$u'$};
\node[below=of u1](u2){$u''$};
\node[below=of u2](u3){$u'''$};
\node[below=of u3](u4){$u^{iv}$};
\node[right=of u0](v0){$v$};
\node[below=of v0](v1){$v'$};
\node[below=of v1](v2){$v''$};
\node[below=of v2](v3){$v'''$};
\node[below=of v3](v4){$v^{iv}$};
\foreach \n/\s[count=\m] in {0/+,1/-,2/+,3/-}\draw[latex-latex](u\n)--node[above]{$\s$}(v\m);
\end{tikzpicture}
\end{document}
循环:
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \p[count=\n] in {,','',''',^{iv}}{
\node(u\n)at(0,-\n){$u\p$};
\node(v\n)at(5,-\n){$v\p$};
}
\foreach \n/\s[evaluate=\n as \m using int(\n+1)] in {1/+,2/-,3/+,4/-}\draw[latex-latex](u\n)--node[above]{$\s$}(v\m);
\end{tikzpicture}
\end{document}