tikz 中的复制和水平翻译

tikz 中的复制和水平翻译

我是 tikz 的新手,我离线找到了此代码,但编码经验很少。我想将五个烧瓶排成一排,箭头指向同一方向。此外,我想添加体积测量。

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{calc, shadings, arrows.meta}

\definecolor{tappo}{RGB}{148,154,110}
\definecolor{lightblue}{RGB}{155,210,220}

\tikzset{
    arrR/.style={-Latex},
    arrL/.style={Latex-}
}

\newcommand\flask[4][arrR]{%
\begin{scope}[shift={(#2)}]
\draw[gray] (-1.8,0) arc (180:0:1.8cm and 6mm);
\begin{scope}
\clip[rounded corners=5mm] (-.5,5) -- (-.5,3.5) -- (-1.8,.5) [sharp corners]-- (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  (1.8,.5) --  (.5,3.5) [sharp corners]-- (.5,5) -- cycle;
\end{scope}

\draw[right color=tappo, left color=tappo, middle color=tappo!40] (.4,4.5) -- (.6,5.5) arc (0:180:6mm and 2mm) -- (-.4,4.5) arc (180:360:4mm and 2mm);
\draw[fill=tappo!60] (0,5.5) ellipse (6mm and 2mm);
\draw[fill=lightblue,rounded corners=5mm, fill opacity=.7] (-.5,5) -- (-.5,3.5) -- (-1.8,.5) [sharp corners]-- (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  (1.8,.5) --  (.5,3.5) [sharp corners]-- (.5,5) arc (360:180:5mm and 2mm);
\draw[fill=lightblue, opacity=.5] (.5,5) to[out=-50,in=230, looseness=2] (-.5,5) arc (180:360:5mm and 2mm);

\begin{scope}[remember picture,overlay,shift={(0,7.5)},rotate=210-(#3*.16)]
\filldraw[black] (-.2,.03) --++ (1,-.01) --++ (0,-.04) --++ (-1,-.01) --++ (0,-.08) --++ (-.05,0) --++ (0,.22) --++ (.05,0) -- cycle;
\end{scope}

\begin{scope}
\draw[#1, line width=.2mm] (1.5,3.9) -- (2.5,3.9) node[right, font=\scriptsize] {#4};

\end{scope}
\begin{scope}[xshift=4mm]

\end{scope}
\end{scope}
}

\begin{document}
\begin{tikzpicture}

\flask{0,0}{0}{1 Molar};
\flask[arrL]{5,0}{130}{0.5 Molar};
\flask[arrL]{10,0}{590}{0.125 Molar};

\end{tikzpicture}
\end{document}

答案1

欢迎来到 TeX:SE!

在您的 MWE(最小工作示例)中,使用以下代码片段绘制了三个烧瓶:

\flask{0,0}{0}{1 Molar};
\flask[arrL]{5,0}{130}{0.5 Molar};
\flask[arrL]{10,0}{590}{0.125 Molar};

如果您希望有更多,只需添加更多代码行,并在它们的中心之间设置所需的水平距离。例如:

\flask{0,0}{0}{1 Molar};
\flask[arrL]{5,0}{130}{0.5 Molar};
\flask[arrL]{10,0}{590}{0.125 Molar};
\flask[arrL]{15,0}{590}{0.125 Molar};
\flask[arrL]{20,0}{590}{0.125 Molar};

在这个距离下,图像会溢出页面。为了防止这种情况,您需要相应地减少距离。例如,如以下 WME 中所做的那样:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, 
                shadings}

\definecolor{tappo}{RGB}{148,154,110}
\definecolor{lightblue}{RGB}{155,210,220}

\tikzset{
    arrR/.style={-Latex},
    arrL/.style={Latex-}
}

\newcommand\flask[4][arrR]{%
\begin{scope}[shift={(#2)}]
\draw[gray] (-1.8,0) arc (180:0:1.8cm and 6mm);
\begin{scope}
\clip[rounded corners=5mm] (-.5,5) -- (-.5,3.5) -- (-1.8,.5) [sharp corners] -- (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  (1.8,.5) --  (.5,3.5) [sharp corners]-- (.5,5) -- cycle;
\end{scope}

\draw[right color=tappo, left color=tappo, middle color=tappo!40] (.4,4.5) -- (.6,5.5) arc (0:180:6mm and 2mm) -- (-.4,4.5) arc (180:360:4mm and 2mm);
\draw[fill=tappo!60] (0,5.5) ellipse (6mm and 2mm);
\draw[fill=lightblue,rounded corners=5mm, fill opacity=.7] (-.5,5) -- (-.5,3.5) -- (-1.8,.5) [sharp corners]-- (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  (1.8,.5) --  (.5,3.5) [sharp corners]-- (.5,5) arc (360:180:5mm and 2mm);
\draw[fill=lightblue, opacity=.5] (.5,5) to[out=-50,in=230, looseness=2] (-.5,5) arc (180:360:5mm and 2mm);

\begin{scope}[remember picture,overlay,shift={(0,7.5)},rotate=210-(#3*.16)]
\filldraw[black] (-.2,.03) --++ (1,-.01) --++ (0,-.04) --++ (-1,-.01) --++ (0,-.08) --++ (-.05,0) --++ (0,.22) --++ (.05,0) -- cycle;
\end{scope}

\begin{scope}
\draw[#1, line width=.2mm] (1,3.9) -- (2,3.9) node[right, font=\scriptsize] {#4};
\end{scope}

\end{scope}
}

\begin{document}
\begin{tikzpicture}

\flask{0,0}{0}{1 Molar};
\flask[arrL]{4.2,0}{130}{0.5 Molar};    % <--- changed
\flask[arrL]{8.4,0}{590}{0.125 Molar};  % <--- changed
\flask[arrR]{12.6,0}{590}{0.125 Molar}; % <--- added
\flask[arrL]{16.8,0}{590}{0.125 Molar}; % <--- added

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

那真是一个很棒的烧瓶!问题是,由于 ,它不能很好地缩放rounded corners。而且一页纸放不下五个。因此,请使用\scalebox并使用普通命令绘制箭头LaTeX。注意:我在烧瓶中添加了一些体积测量值。

在此处输入图片描述

\scaleflask我创建了一个带有一个可选参数的新命令。

\scaleflask[.3]

.3是(可选)缩放因子(默认值 = 1)。

在此处输入图片描述

代码

\[
\scaleflask[.3]\xleftarrow{\textstyle1.0\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.5\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.25\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.13\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.06\Molar}
\]

创建上面的图像。以下是完整代码:

\documentclass{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{shadings}

\definecolor{tappo}{RGB}{148,154,110}
\definecolor{lightblue}{RGB}{155,210,220}

\newcommand\flask[1][1]{\begin{tikzpicture}
    \draw[gray] (-1.8,0) arc (180:0:1.8cm and 6mm);
    \begin{scope}
        \clip[rounded corners=5mm] (-.5,5) -- (-.5,3.5) -- (-1.8,.5) [sharp corners]-- 
            (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  (1.8,.5) --  
            (.5,3.5) [sharp corners]-- (.5,5) -- cycle;
    \end{scope}
    \draw[right color=tappo, left color=tappo, middle color=tappo!40] (.4,4.5) -- 
        (.6,5.5) arc (0:180:6mm and 2mm) -- (-.4,4.5) arc (180:360:4mm and 2mm);
    \draw[fill=tappo!60] (0,5.5) ellipse (6mm and 2mm);
    \draw[fill=lightblue,rounded corners=5mm, fill opacity=.7] (-.5,5) -- (-.5,3.5) -- 
        (-1.8,.5) [sharp corners]-- (-1.8,0) arc (180:360:1.8cm and 6mm) [rounded corners=5mm]--  
        (1.8,.5) --  (.5,3.5) [sharp corners]-- (.5,5) arc (360:180:5mm and 2mm); 
    \draw[fill=lightblue, opacity=.5] (.5,5) to[out=-50,in=230, looseness=2] (-.5,5) arc (180:360:5mm and 2mm);
    \foreach \y[count=\n, evaluate=\n as \m using int(50*\n), evaluate=\y as \k using 18-\y^(3/2)/14] in {4,10,17,25}{
    \draw[white, thick, yshift=\y mm]([xscale=3]250:.333*\k mm) arc(250:280:\k mm and .333*\k mm)node[rotate=4, right]{\sffamily \m};}
\end{tikzpicture}}

\newcommand{\scaleflask}[1][1]{\vcenter{\hbox{\scalebox{#1}{\flask}}}}
\newcommand{\Molar}{\textup{ Molar}}

\begin{document}

\[
\scaleflask[.3]\xleftarrow{\textstyle1.0\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.5\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.25\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.13\Molar}
\scaleflask[.3]\xleftarrow{\textstyle0.06\Molar}
\]

\end{document}

相关内容