在多个位置进行标记

在多个位置进行标记

我正在画一个带有 ti 的 DNA 符号图像頁面: 含核苷酸的 DNA 我使用以下方法完成此操作decorations.markings

\documentclass[margin = 12mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}\begin{tikzpicture}
  \newcommand*{\adenin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = red]%
        \fill(0, -.1) -- (.35, -.1) -- (.45, 0) -- (.35, .1) -- (0, .1) -- cycle;%
  \end{scope}}%
  \newcommand*{\thymin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = blue]%
        \fill(0, -.1) -- (.35, -.1) -- (.25, 0) -- (.35, .1) -- (0, .1) -- cycle;
  \end{scope}}%
  \newcommand*{\guanin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = green]%
        \fill(0, -.1) -- (.35, -.1) arc(-90:90:.1) -- (.35, .1) -- (0, .1) -- cycle;% -- (0, .1) -- cycle;%
  \end{scope}}%
  \newcommand*{\cytosin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = yellow]%
        \fill(0, -.1) -- (.35, -.1) arc(270:90:.1) -- (.35, .1) -- (0, .1) -- cycle;%
  \end{scope}}%

  \draw[double distance = 1pt, line cap = rect, decoration = {
        markings, 
        mark = at position 5pt with { \adenin{(0, 0)}{270} },
        % 200 more lines with at position ...
        mark = at position 370pt with { \cytosin{(0, 0)}{270}{1.25} }
     }, preaction = {decorate}, shorten <= -3pt]
        (-.5, -1.2) .. controls (2, 1) and (4, -1) .. (6, 0)
        .. controls (9, 1.5) and (10, 0) .. (12, 0);
        % the other three paths with each 200 lines with at position...
\end{tikzpicture}\end{document}

根据z 手册,31.5 标记只能使用以下任一方式指定

/pgf/decoration/mark=at position <pos> with <code>

哪里<pos>数字或

/pgf/decoration/mark=between positions <start pos> and <end pos> step <stepping> with <code>

这个只是为了定期重复的标记,但事实并非如此。

因为看起来没有办法指定标记位置的列表,所以我认为最简单的方法是对每个位置进行循环,但我不知道如何将循环放在选项定义中。

虽然这不会改变任何结果,但我对如何简化我的代码很感兴趣。抱歉,示例太长了。提前感谢你的帮助

答案1

我会做些稍微不同的事情。我会将哪种蛋白质应该位于列表中的哪个位置的信息存储起来,并指示标记使用此列表。我添加了一个命令\somein,它接受一个参数,根据参数是否为、、或,\adenin{(0, 0)}{270}扩展为 \thymin{(0, 0)}{270}、、或。(也可以编写一个命令,接受蛋白质的名称或等等。)然后有一个列表,指示哪种蛋白质应该位于位置 1、2 等。\guanin{(0, 0)}{270}\cytosin{(0, 0)}{270}1234AB

\documentclass[margin = 12mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}\begin{tikzpicture}
  \newcommand*{\adenin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = red]%
        \fill(0, -.1) -- (.35, -.1) -- (.45, 0) -- (.35, .1) -- (0, .1) -- cycle;%
  \end{scope}}%
  \newcommand*{\thymin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = blue]%
        \fill(0, -.1) -- (.35, -.1) -- (.25, 0) -- (.35, .1) -- (0, .1) -- cycle;
  \end{scope}}%
  \newcommand*{\guanin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = green]%
        \fill(0, -.1) -- (.35, -.1) arc(-90:90:.1) -- (.35, .1) -- (0, .1) -- cycle;% -- (0, .1) -- cycle;%
  \end{scope}}%
  \newcommand*{\cytosin}[2]{\begin{scope}[shift = {#1}, rotate = #2, fill = yellow]%
        \fill(0, -.1) -- (.35, -.1) arc(270:90:.1) -- (.35, .1) -- (0, .1) -- cycle;%
  \end{scope}}%
  \newcommand*{\somein}[1]{\ifcase#1
  \or 
  \adenin{(0, 0)}{270}
  \or
  \thymin{(0, 0)}{270}
  \or
  \guanin{(0, 0)}{270}
  \or
  \cytosin{(0, 0)}{270}
  \fi
  } 
  \newcommand\myinlst{3, 1, 2, 2, 2, 2, 1, 3, 1, 4, 2, 2, 1, 1, 3, 4, 1, 
 2, 4, 4, 4, 4, 4, 4, 2, 2, 3, 1, 3, 4, 1, 4, 1, 4, 
 2, 3, 2, 4, 3, 4, 2, 3, 3, 2, 2, 3, 2, 1, 3, 1, 2, 
 3, 4, 3, 2, 4, 1, 2, 4, 4, 3, 3, 1, 1, 1, 4, 3, 4, 
 2, 2, 1, 2, 2, 2, 2, 2, 1, 4, 4, 1, 3, 4, 1, 1, 1, 
 3, 1, 2, 3, 3, 4, 2, 4, 3, 3, 3, 4, 2, 3, 2}
  \draw[double distance = 1pt, line cap = rect, decoration = {
        markings, 
        mark=between positions 5pt and 0.99 step 10pt
         with
        {\pgfmathtruncatemacro{\myin}{{\myinlst}[\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}-1]}
         \somein{\myin}},
        % 200 more lines with at position ...
     }, preaction = {decorate}, shorten <= -3pt]
        (-.5, -1.2) .. controls (2, 1) and (4, -1) .. (6, 0)
        .. controls (9, 1.5) and (10, 0) .. (12, 0);
        % the other three paths with each 200 lines with at position...
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

感谢 AndréC 的评论,我使用列表解决了这个问题:

\begin{document}\begin{tikzpicture}[
        adenin/.style = {decoration = {markings,
        mark = at position #1 with { \adenin{(0, 0)}{270} }
  }}, thymin/.style = {decoration = {markings,
        mark = at position #1 with { \thymin{(0, 0)}{270} }
  }}, guanin/.style = {decoration = {markings,
        mark = at position #1 with { \guanin{(0, 0)}{270} }
  }}, cytosin/.style = {decoration = {markings,
        mark = at position #1 with { \cytosin{(0, 0)}{270} }
  }}]

对于每个核苷酸,然后将它们称为:

     \draw[double distance = 1pt, line cap = rect,
        thymin/.list = {5pt, 15pt, 35pt},
        adenin/.list = {25pt, 45pt, 55pt},
        guanin/.list = {75pt, 85pt, 115pt},
        cytosin/.list = {65pt, 95pt, 105pt},
      preaction = {decorate}, shorten <= -3pt]
        (-.5, -1.2) .. controls (2, 1) and (4, -1) .. (6, 0)

然而,这违反了必须沿路径放置标记的原则:

然而,在使用多个标记的情况下,路径上的位置必须按升序排列。(pgf 手册第 384 页)。

因此,标记的位置非常奇怪: 奇怪的标记

相关内容