如何使用 TikZ 注释图形而不影响浮动位置?蛋白质印迹的模板

如何使用 TikZ 注释图形而不影响浮动位置?蛋白质印迹的模板

我想制作一些图表,这是生物学中典型的蛋白质印迹图。这些图表使用包括在框架中mdframed。下面显示了一个 MWE 示例。在创建这组图表的过程中,出现了一些问题。下图的位置发生了位移,代码很混乱,我说如果我继续这样做,它会更加混乱。因此,我决定在得到一行行糟糕的代码之前向社区寻求帮助。

需要什么:

  1. 在每个箭头(共有 6 个)旁边(右侧)放置一个数字,以指示迁移蛋白质的大小,例如,数字如、 、 、 、10kDa15kDa25kDa35kDa到上)。如果代码将其视为相对坐标而不是绝对坐标,将会很有帮助(非常感谢,因为我会将相同的箭头及其相应的数字标签应用于其余图形)。40kDA55kDa
  2. 斑点上方的标签应保持45旋转度数,如果它们被90旋转,则下图不会发生位移,如下所示。那么在这种情况下,应该怎么做才能避免这种不必要的位移行为?
  3. 以相同的方式将度数45旋转的标签应用于另外两个图形,并确保这不会导致类似的图形位移。
  4. 确实,提供快捷代码会很有帮助,TikZ这样可以减少注释此类图片所需的已经很混乱的代码量。
  5. 标签beta-actin应放在 MWE 中所示的每个较大图形下方的小图形的左侧。这会导致较小图形进一步位移(如果将 MWE 的图形 c 与实际图形 c 进行比较)。此标签应以完全相同的方式应用于其余两个上述图形,而不会引起任何副作用。

MWE 代码:

\documentclass{scrartcl}
\usepackage{xcolor} 
\usepackage{caption}
\usepackage{floatrow}   
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc,decorations.markings}

\begin{document}
\begin{figure}
\begin{mdframed}[
  align=center,
  linecolor=black,
  fontcolor=black,
  backgroundcolor=white,
  userdefinedwidth=0.9\textwidth,
  roundcorner=5pt,
  skipabove=0pt,
  skipbelow=0pt,
  leftmargin=0pt,
  innerleftmargin=20pt,
  innerrightmargin=0pt,
  innertopmargin=5pt,
  innerbottommargin=5pt, 
  innerlinewidth=0pt,
  middlelinewidth=0pt,
  outerlinewidth=1pt]
\floatsetup[subfigure]{captionskip=10pt}
%===================== upper two subfigures ================
\begin{minipage}{.44\textwidth}
    \begin{subfigure}{\linewidth}
    \centering
    \begin{tikzpicture}[remember picture]
     \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (a) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0 0 0 0]{whatever}};
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture]
    \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (asupp) {\includegraphics[width=5cm,height=.75cm, clip= true, trim = 0 0 0 0]{whatever}};
    \end{tikzpicture}
    \caption{Image}
    \label{fig:mwe:a}
    \end{subfigure}\\[0ex]
\end{minipage}
\begin{minipage}{.44\textwidth}
    \begin{subfigure}{\linewidth}
    \centering
    \begin{tikzpicture}[remember picture]
        \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (b) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0 0 0 0]{whatever}};
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture]
        \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (bsupp) {\includegraphics[width=5cm, height=.75cm, clip= true, trim = 0 0 0 0]{whatever}};
    \end{tikzpicture}
    \caption{Image}
    \label{fig:mwe:b}
   \end{subfigure}
\end{minipage}
\vfill
%===================== the one below subfigure ================
\begin{minipage}{.94\textwidth}
  \begin{subfigure}{\linewidth}
  \centering
  \begin{tikzpicture}[remember picture]
 \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (c) 
    {\includegraphics[width=5cm, height=5cm, clip= true, trim = 35 0 0 0]{whatever}};
  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,.2); %arrowhead

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,1.6);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3.6);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.1);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.6);

    % add labels
    \node [anchor=south west, xshift=35pt, rotate=45] at (c.north west) {Lane1 ABC};

    \node [anchor=south west, xshift=70pt, rotate=45] at (c.north west) {Lane2 DEF};

    \node [anchor=south west, xshift=105pt, rotate=45] at (c.north west) {Lane3 GHI};

    \node [anchor=south west, xshift=135pt, rotate=45] at (c.north west) {Lane4 JKL};
  \end{tikzpicture}
  \\[0ex]
  \begin{tikzpicture}[remember picture]
   \node [anchor=south west, draw=orange,line width=5pt, inner sep=0pt] (csupp) {\includegraphics[width=5cm, height=.75cm, clip= true, trim = 0 0 0 0]{whatever}};
   \node[anchor=south west,font=\ttfamily,xshift=-50] at (csupp.south west) {$\beta$-actin};
  \end{tikzpicture}
  \caption{Image}
  \label{fig:mwe:c}
  \end{subfigure} 
\end{minipage}

\end{mdframed}
\RawCaption{\caption{General Caption.}
\label{fig:mwe}}
\end{figure}

\end{document}

得出的结果是:
在此处输入图片描述

例如,图形 c 在原始图像中如下所示:
在此处输入图片描述

更新:
代码现已更新,以便 MWE 可以使用\usepackage[demo]{graphicx}选项使用演示图像。

答案1

按照 OP 的要求,扩展我的评论,这个想法是将每个图形的边界框强制到包含所包含图形的区域。这很容易,因为图形包含在一个节点中。

例如,如果节点的名称是c,则只需将以下路径作为的一部分包含在内tikzpicture

\path[use as bounding box] (c.south west) rectangle (c.north east);

TeX 会考虑这个矩形,以便为图形保留空间,从而进行对齐。在该矩形之外绘制的所有内容都会“溢出”tikz 图片,并可能与周围的文本重叠。为了避免这种情况,您必须手动在 tikz 图片周围设置一些垂直或水平空间。

在您的示例中,子图 (c) 必须“手动”向下移动,以避免顶部的旋转标签与图 (a) 和 (b) 发生冲突。这意味着\vskip在它们之间插入一些。

这是完整的代码(更改部分已用% <===注释标记)

\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{floatrow}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc,decorations.markings}

\begin{document}
\begin{figure}
\begin{mdframed}[
  align=center,
  linecolor=black,
  fontcolor=black,
  backgroundcolor=white,
  userdefinedwidth=0.9\textwidth,
  roundcorner=5pt,
  skipabove=0pt,
  skipbelow=0pt,
  leftmargin=0pt,
  innerleftmargin=20pt,
  innerrightmargin=0pt,
  innertopmargin=5pt,
  innerbottommargin=5pt,
  innerlinewidth=0pt,
  middlelinewidth=0pt,
  outerlinewidth=1pt]
\floatsetup[subfigure]{captionskip=10pt}
%===================== upper two subfigures ================
\begin{minipage}{.44\textwidth}
    \begin{subfigure}{\linewidth}
    \centering
    \begin{tikzpicture}[remember picture]
     \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (a) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0 0 0  → 0]{whatever}};
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture]
    \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (asupp) {\includegraphics[width=5cm,height=.75cm, clip= true, trim = 0  → 0 0 0]{whatever}};
    \end{tikzpicture}
    \caption{Image}
    \label{fig:mwe:a}
    \end{subfigure}\\[0ex]
\end{minipage}
\begin{minipage}{.44\textwidth}
    \begin{subfigure}{\linewidth}
    \centering
    \begin{tikzpicture}[remember picture]
        \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (b) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0   → 0 0 0]{whatever}};
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture]
        \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (bsupp) {\includegraphics[width=5cm, height=.75cm, clip= true,      → trim = 0 0 0 0]{whatever}};
    \end{tikzpicture}
    \caption{Image}
    \label{fig:mwe:b}
   \end{subfigure}
\end{minipage}
\vskip 2cm  % <==== Needed to "make room" for the rotated labels
%===================== the one below subfigure ================
\begin{minipage}{.94\textwidth}
  \begin{subfigure}{\linewidth}
  \centering
  \begin{tikzpicture}[remember picture]
 \node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (c)
    {\includegraphics[width=5cm, height=5cm, clip= true, trim = 35 0 0 0]{whatever}};
  \path[use as bounding box] (c.south west) rectangle (c.north east);  % <===== 
  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,.2); %arrowhead

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,1.6);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3.6);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.1);

  \path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.6);

    % add labels
    \node [anchor=south west, xshift=35pt, rotate=45] at (c.north west) {Lane1 ABC};

    \node [anchor=south west, xshift=70pt, rotate=45] at (c.north west) {Lane2 DEF};

    \node [anchor=south west, xshift=105pt, rotate=45] at (c.north west) {Lane3 GHI};

    \node [anchor=south west, xshift=135pt, rotate=45] at (c.north west) {Lane4 JKL};
  \end{tikzpicture}
  \\[0ex]
  \begin{tikzpicture}[remember picture]
   \node [anchor=south west, draw=orange,line width=5pt, inner sep=0pt] (csupp) {\includegraphics[width=5cm, height=.75cm, clip= true, trim =   → 0 0 0 0]{whatever}};
   \path[use as bounding box] (csupp.south west) rectangle (csupp.north east);  % <======
   \node[anchor=south west,font=\ttfamily,xshift=-50] at (csupp.south west) {$\beta$-actin};
  \end{tikzpicture}
  \\[0ex]
  \caption{Image}
  \label{fig:mwe:c}
  \end{subfigure}
\end{minipage}

\end{mdframed}
\RawCaption{\caption{General Caption.}
\label{fig:mwe}}
\end{figure}

\end{document}

结果如下:

结果

相关内容