T_C
如何使用和T_zero
锚点使红线与上面的两条线平行?
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes,positioning,intersections,quotes,patterns,patterns.meta,shapes.misc,shapes.geometric,calc}
\definecolor{viola}{HTML}{8100FF}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\node[] (cold_in) at (5,0) {};
\node[] (cold_out) at (0,0) {};
\draw[gray] (cold_out) -- (cold_in);
\node[anchor=north west,rectangle] (T_C) at (cold_in.south east) {$T_{C,L}$};
\node[anchor=north east,rectangle] (T_zero) at (cold_out.south west) {$T_0$};
\draw[->,dotted] (T_C) -- (T_zero);
\node[anchor=north west] (hot_in) at (T_zero.south east) {};
\node[anchor=north east] (hot_out) at (T_C.south west) {};
\draw[red] (hot_out) -- (hot_in);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
您可以使用以下(简单、简短的)代码绘制节点之间带有直线的图像:
\documentclass[12pt, margin=3mm]{standalone}
\usepackage{tikz}
% commented libraries and packages are not needed in this example
\usetikzlibrary{arrows.meta,
%calc,
%intersections,,
%shapes,
%patterns, patterns.meta, positioning,
%quotes,
%shapes.misc, shapes.geometric
}
%\definecolor{viola}{HTML}{8100FF}
%\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[
N/.style = {minimum height=3ex, text depth=0.25ex},
shorten <>/.style = {shorten > = #1, shorten <=#1}
]
\node (cold_in) [N, right] at (5,0) {$T_{C,L}$};
\node (cold_out) [N, left] at (0,0) {$T_0$};
\draw[gray, shorten <>=3mm] (cold_out.north east) -- (cold_in.north west);
\draw[red, shorten <>=3mm] (cold_out.south east) -- (cold_in.south west);
\draw[-Straight Barb,dotted] (cold_in) -- (cold_out);
\end{tikzpicture}
\end{document}
答案2
我建议稍微简化它,但仍然使用节点的锚点。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes,positioning,intersections,quotes,patterns,patterns.meta,shapes.misc,shapes.geometric,calc}
\definecolor{viola}{HTML}{8100FF}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\node[above left,minimum height=1cm,inner ysep=0pt] (T_C) at (5,0) {$T_{C,L}$};
\node[above right,minimum height=1cm,inner ysep=0pt] (T_zero) at (0,0) {$T_0$};
\draw[->,dotted] (T_C) -- (T_zero);
\node[anchor=north west] (hot_in) at (T_zero.south east) {};
\node[anchor=north east] (hot_out) at (T_C.south west) {};
\draw[gray] (T_zero.north east) -- (T_C.north west);
\draw[red] (T_zero.south east) -- (T_C.south west);
\end{tikzpicture}
\end{figure}
\end{document}