为所有节点定义相等的 xshift 或 yshift

为所有节点定义相等的 xshift 或 yshift

我对 tikz 还不熟悉,我正在根据模板绘制流程图。我目前正在为每个节点分别定义 xshift 和 yshift:

\documentclass[11pt,a4paper]{scrartcl}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{pdflscape}
\usepackage{geometry}
\usepackage{tikz} %call package for drawing
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows.meta}



\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows.meta}

\tikzset{%
  >={Latex[width=2mm,length=2mm]},
  % Specifications for style of nodes:
            base/.style = {rectangle, draw=black,
                           minimum width=2cm, minimum height=0.75cm,
                           text centered, %font=\sffamily
                       },
  mystyle/.style = {base, fill=orange!40},
}

\begin{document}
    \begin{landscape}

\begin{tikzpicture}[node distance=1.5cm,
    every node/.style={fill=white, font=\sffamily}, align=center]

\node (mynode) [mystyle] {mynode};
\node (mynode2) [mystyle, right of=mynode, xshift=3cm, yshift=2cm] {mynode2};
\node (mynode3) [mystyle, right of=mynode2, xshift=3cm] {mynode3};

\end{tikzpicture}
\end{landscape}
\end{document}

有没有办法指定 应该xshift 始终是序言中定义的某个值?现在应该是xshift = 3cm,但也许以后我会改变主意,想把它改成 2cm,所以有一个方便的方法来做到这一点会很好。此外,我仍然希望保留定义单个节点定位的选项(因此也许几乎所有xshift选项都应该是3cm,除了一个我需要手动指定的选项4cm)。

答案1

您可以编辑以下代码

  mystyle/.style = {base, fill=orange!40, xshift=3cm},

在此处输入图片描述

\documentclass[11pt,a4paper]{scrartcl}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{pdflscape}
\usepackage{geometry}
\usepackage{tikz} %call package for drawing
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows.meta}



\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows.meta}

\tikzset{%
  >={Latex[width=2mm,length=2mm]},
  % Specifications for style of nodes:
            base/.style = {rectangle, draw=black,
                           minimum width=2cm, minimum height=0.75cm,
                           text centered, %font=\sffamily
                       },
  mystyle/.style = {base, fill=orange!40, xshift=3cm},
}

\begin{document}
    \begin{landscape}

\begin{tikzpicture}[node distance=1.5cm,
    every node/.style={fill=white, font=\sffamily}, align=center]

\node (mynode) [mystyle] {mynode};
\node (mynode2) [mystyle, right of=mynode,  yshift=2cm] {mynode2};
\node (mynode3) [mystyle, right of=mynode2,] {mynode3};

\end{tikzpicture}
\end{landscape}
\end{document}

相关内容