# Improve this TikZ schematic drawing of HPLC

I am learning TikZ (which is a very elegant alternative to Inkscape and its workflow), however I am not very good at it at the moment.

I am trying to recreate this .svg which was done with Inkscape.

Here is the .tex ...

\documentclass[12pt,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}[scale=1]
\draw (0,0) rectangle (2,2.5) node[midway,align=center](Eluent) {};
\draw (0,0) rectangle (2,2);%To simulate a filled cylinder.

\draw (3,0) rectangle (7.5,2.5) node[above,midway,align=center](HPLC) {};

\draw (12.5,0) rectangle (13.5,2.5) node[midway,align=center](Probe) {};
\draw (12.5,0) rectangle (13.5,2);%To simulate a filled cylinder.

\draw (8.5,3.5) rectangle (10,6) node[align=center,midway](Probeschleife) {};

\draw  (16.5,0) rectangle (20.5,-2.5) node[pos=0.5](Detektor) {};

\draw (10,8) rectangle (14,9) node[midway](Trenns){};

\begin{scope}[on background layer]
\draw [-to] (HPLC.north) |- (Probeschleife.west);
\draw [-to](Probe.north) |- (Probeschleife.east);
\draw [-to](Eluent) -- (HPLC);
\draw [-to] (Probeschleife.north) |- (Trenns.west);
\draw [-to] (Trenns.east) -- (18.5,8.5) -- (Detektor.north); %the middle coordinate is to move the path out of the main picture.
\end{scope}

%labels
\node [below] (Eluent) at (1,0) {Eluent};
\node [below] (HPLC) at (5.25,0) {HPLC-Pumpe};
\node [below] (Probe) at (13,0) {Probe};
\node [below] (Detektor) at (18.5,-2.5) {Detektor};
\node [left] (Probeschleifer) at (9.25,3.5) {Probeschleifer};
\node [below] (Trenns) at (12,8) {Trennsäule};

\end{tikzpicture}
\end{document}


... which compiles to this PDF (I added the red arrows and boxes to show the issues):

I am trying to fix the following problems:

1. In the original diagram, the line connects "Eluent" and "HPLC-Pumpe" in the dashed way.

2. In the diagram, all of the lines which exit a part of the machine leave at the top / east side of the part. The red arrows show that this isn't the case.

3. I'd like to move the label of "Probeschleifer" away from the rectangle, to avoid overlaps.

4. I calculated the coordinates (18.5,8.5) by hand (by printing out the original Inkscape and measuring the distances). Is there a way to adjust the path from "Trennsäule" to "Detektor" easily, without it overlapping the diagram, i.e. going through the path "Probe -- Probeschleife[r]"? (Typo: should be ...schleife).

5. Is there a way to automatically have the labels offset? I.e. if I move one of the rectangles, I will also have to move the node.

• It would help if all of the solid bodies were shaded solidly, so they are more easily distinguished from the connectors. – Benjamin McKay Feb 10 at 14:11
• @BenjaminMcKay Do you mean shaded with color or with a pattern? – Max R Feb 10 at 18:38
• You can also create a named rectangle using \begin{scope}[local bounding box=name] ... \end{scope}. – John Kormylo Feb 10 at 18:44
• @MaxR: with color, please. – Benjamin McKay Feb 10 at 19:56

This is a draft that illustrates the advantage of using \node instead of drawing rectangles with the \draw command.

Indeed, the arrows between two nodes go from edge to edge and do not cross them.

This greatly facilitates this kind of diagram. Then, the nodes are positioned relative to each other with the positioning library.

I have commented (without deleting them) the lines of your code and written just below how they have been modified.

I didn't try to simplify the code so that you could read it easily.

The second part of the node is colored in cyan. I have improved the code of the dotted line to give you more flexibility in its use.

\documentclass[12pt,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{shapes.multipart}
\begin{document}

\begin{tikzpicture}[scale=1]
%\draw (0,0) rectangle (2,2.5) node[midway,align=center](Eluent) {};
%\draw (0,0) rectangle (2,2);%To simulate a filled cylinder.
\node[draw,minimum width=2cm,minimum height=2.5cm,rectangle split,rectangle split parts=2,rectangle split empty part height=1.8cm,rectangle split part fill={white,cyan!50}](Eluent){\phantom{a}};

%\draw (3,0) rectangle (7.5,2.5)
\node[draw,minimum width=4.5cm,minimum height=2.5cm,right=20mm of Eluent](HPLC) {};

%\draw (12.5,0) rectangle (13.5,2.5)
\node[draw,minimum width=1cm,minimum height=2.5cm,rectangle split,rectangle split parts=2,rectangle split empty part height=1.8cm,right= 40mm of HPLC](Probe) {\phantom{a}};

%\draw (12.5,0) rectangle (13.5,2);%To simulate a filled cylinder.
%\draw (8.5,3.5) rectangle (10,6)
\node[draw,minimum width=1.5cm,minimum height=2.5cm,above right=of HPLC](Probeschleife) {};

%\draw  (16.5,0) rectangle (20.5,-2.5)
\node[draw,minimum width=4cm,minimum height=2.5cm,above right=of Probeschleife](Detektor) {};

%\draw (10,8) rectangle (14,9)
\node[draw,minimum width=4cm,minimum height=1cm,below right=80mm and 10mm of Detektor](Trenns){};

\node[above right= 10mm and 10mm of Eluent](aux1){};
\draw[densely dotted, thick](Eluent) |-(aux1.center)|-  (HPLC.200);
\begin{scope}[on background layer]
%\draw [-to] (HPLC.north) |- (Probeschleife.west);
%\draw [-to](Probe.north) |- (Probeschleife.east);
%\draw [-to](Eluent) -- (HPLC);
%\draw [-to] (Probeschleife.north) |- (Trenns.west);
%\draw [-to] (Trenns.east) -- (18.5,8.5) -- (Detektor.north); %the middle coordinate is to move the path out of the main picture.
\end{scope}

%labels
\node [below=0mm of Eluent] {Eluent};
\node [below=0mm of HPLC]{HPLC-Pumpe};
\node [below=0mm of Probe] {Probe};
\node [below=0mm of Detektor] {Detektor};
\node [below left=-5mm and 0mm of Probeschleife] {Probeschleifer};
\node [below=0mm of Trenns] {Trennsäule};

\end{tikzpicture}
\end{document}

• Thank you! This answer is flexible enough for me to edit and add new parts without calculating everything anew. – Max R Feb 10 at 12:26
• How can I only fill out part of the "Eluent" rectangle, @AndréC ? So that the bottom rectangle is blue, for example. – Max R Feb 10 at 12:36
• My compliments teacher for your work. – Sebastiano Feb 10 at 13:04
• @MaxR Seee my update, i updated too the code of the dashed line. :-) – AndréC Feb 10 at 13:22
• @Sebastiano thanks you :-) – AndréC Feb 10 at 13:23

So, here is the final version: And here is the .tex:

\documentclass[11pt,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{patterns}
\begin{document}
{\fontfamily{cmss}\selectfont
\begin{tikzpicture}
\node[draw,thick,minimum width=2cm,minimum height=2.5cm,rectangle split,rectangle split parts=2,rectangle split empty part height=1.8cm, rectangle split part fill={white,cyan!60}](Eluent){\phantom{a}};

\node[draw,thick,minimum width=4.5cm,minimum height=2.5cm,right=20mm of Eluent,fill=gray!40](HPLC){};

\node[draw,thick,minimum width=1cm,minimum height=2.5cm,rectangle split,rectangle split parts=2,rectangle split empty part height=1.8cm,right= 60mm of HPLC,rectangle split part fill={white,cyan!60}](Probe) {\phantom{a}};

\node[draw,thick,minimum width=2cm,minimum height=3.5cm,above right=of HPLC,fill=yellow!40](Probeschleife){};

\node[draw,thick,minimum width=1cm,minimum height=1cm,above right=of Probeschleife, pattern=dots](TrennsIn){};
\node[draw,thick,minimum width=1cm,minimum height=1cm,right=40mm of TrennsIn, pattern=dots](TrennsOut){};
\draw[double distance between line centers =.3cm,thick] (TrennsIn) -- node[midway,below=1.5mm] {Trennsäule} (TrennsOut);
\node[draw,thick,minimum width=4cm,minimum height=2.5cm, right=30mm of Probe,fill=gray!40](Detektor){};

\node[above right= 10mm and 10mm of Eluent](aux1){};
\draw[-latex,thick](Eluent) |-(aux1.center)|-  (HPLC);

%\draw[-latex](Eluent) -- (HPLC);
\draw[-latex,thick](HPLC) |- (Probeschleife);
\draw[-latex,thick](Probe) |- (Probeschleife);
\draw[-latex,thick](Probeschleife) |- (TrennsIn);
\draw[-latex,thick](TrennsOut) -| (Detektor);
%labels
\node [below=0mm of Eluent] {Eluent};
\node [below=0mm of HPLC]{HPLC-Pumpe};
\node [below=0mm of Probe] {Probe};
\node [below=0mm of Detektor] {Detektor};
\node [below left=-5mm and 0mm of Probeschleife] {Probeschleifer};

\end{tikzpicture}
}
\end{document}


The font is now sans serif, which will be my standard for diagrams in my thesis. I really liked how the "Trennsäule" turned out. If you have any feedback, please share. Thanks!

• You can use \tikzset styles to lighten the code by factoring in identical options. For example, there are blue and grey figures that have a common style (options). – AndréC Feb 10 at 20:46