tikz での複製と水平方向の翻訳

tikz での複製と水平方向の翻訳

私は tikz 初心者で、このコードをオフラインで見つけましたが、コーディングの経験はほとんどありません。フラスコを 5 つ並べて、矢印をフラスコの方向に同じ方向に向けたいと思います。さらに、体積測定を追加したいと思います。

\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 (最小限の動作例) には、次のコード フラグメントで 3 つのフラスコが描かれています。

\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。また、5 つでは 1 ページに収まりません。そのため、 と を使用して\scalebox、通常のコマンドで矢印を描画しますLaTeX。注: フラスコにいくつかの容量測定値を追加しました。

ここに画像の説明を入力してください

オプションの引数を 1 つ取る新しいコマンドを作成しました\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}

関連情報