Duplizierung und horizontale Übersetzung in Tikz

Duplizierung und horizontale Übersetzung in Tikz

Ich bin neu bei Tikz. Ich habe diesen Code offline gefunden, habe aber nur minimale Erfahrung mit dem Programmieren. Ich möchte fünf Flaschen in einer Reihe haben, mit Pfeilen, die in die gleiche Richtung auf die Flaschen zeigen. Außerdem möchte ich Volumenmessungen hinzufügen.

\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}

Antwort1

Willkommen bei TeX:SE!

In deinem MWE (minimal working example) sind mit folgendem Codefragment drei Flasks eingezeichnet:

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

Wenn Sie mehr davon haben möchten, fügen Sie einfach weitere Codezeilen mit dem gewünschten horizontalen Abstand zwischen ihren Mittelpunkten hinzu. Beispiel:

\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};

Bei diesem Abstand läuft das Bild über die Seite hinaus. Um dies zu verhindern, müssen Sie die Abstände entsprechend verringern. Dies wird beispielsweise im folgenden WME gemacht:

\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}

Bildbeschreibung hier eingeben

Antwort2

Das ist ein wirklich schöner Kolben! Das Problem ist, dass er wegen nicht gut skaliert rounded corners. Und fünf davon passen nicht auf eine Seite. Verwenden Sie also \scaleboxdie Pfeile und zeichnen Sie sie mit normalen LaTeXBefehlen. Hinweis: Ich habe dem Kolben einige Volumenmaße hinzugefügt.

Bildbeschreibung hier eingeben

Ich habe einen neuen Befehl erstellt \scaleflask, der ein optionales Argument annimmt.

\scaleflask[.3]

.3ist der (optionale) Skalierungsfaktor (Standard=1).

Bildbeschreibung hier eingeben

Der Code

\[
\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}
\]

erstellt das obige Bild. Hier ist der vollständige Code:

\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}

verwandte Informationen