在 LaTeX 中创建一个简单的 2 面板图表

在 LaTeX 中创建一个简单的 2 面板图表

我正在尝试用 LaTeX 制作双面板图表。我不知道它会有多复杂。有人能建议创建此类图表的起点是什么吗?

图表如下:

在此处输入图片描述

我将非常感激您的任何建议。

答案1

在此处输入图片描述

CAD包中的模块可以Asymptote提供帮助。下面 p.tex将生成一个panel.asy文件,其中包含类(结构)的简要概述Panel,它具有简单的结构,如果需要,可以轻松进一步定制。有关operator init详细信息,请参阅。

\begin{filecontents*}{panel.asy}
import CAD;

struct Panel{
  real Tc, QpR, D;
  real blockHeight, blockTop; 
  int nSections;
  real xtipSize,ytipSize;
  sCAD cad;
  void drawGraph(){
    draw(g=(0,0)*cm--(Tc,QpR)*cm--(D,QpR)*cm--(D+Tc,0)*cm,cad.pA);
    draw(g=(D+Tc,0)*cm--(D+Tc,QpR)*cm,cad.pB);
    cad.MeasureParallel(L = "$Q_{pR}$",
      pFrom = (Tc, 0)*cm,
      pTo = (Tc, QpR)*cm,
      dblDistance = 0mm);
    cad.MeasureParallel(L = "$T_{c}$",
      pFrom = (0, QpR)*cm,
      pTo = (Tc, QpR)*cm,
      dblDistance = 2mm);
    cad.MeasureParallel(L = "$T_{c}$",
      pFrom = (D, QpR)*cm,
      pTo = (D+Tc, QpR)*cm,
      dblDistance = 2mm);    
  }

  void drawBlock(){
    real dx=D/nSections;
    for(int i=1;i<nSections;++i){
      draw(((i*dx, blockTop-blockHeight)*cm--(i*dx, blockTop)*cm),cad.pB);
    }
    draw(box((0, blockTop-blockHeight)*cm, (D, blockTop)*cm),cad.pA);

    cad.MeasureParallel(L = "$D$",
      pFrom = (0, blockTop)*cm,
      pTo = (D, blockTop)*cm,
      dblDistance = 2mm);
  }
  void drawAxes(){
    draw((0,0)*cm--(D+Tc+xtipSize,0)*cm,cad.pB,Arrow(HookHead,size=1mm));
    draw((0,0)*cm--(0,blockTop+1+ytipSize)*cm,cad.pB,Arrow(HookHead,size=1mm));
  }

  void drawYLabel(){
    label(rotate(90)*Label("Discharges (cms)")
    ,0.5(0,blockTop+1+ytipSize)*cm
    ,W);
  }

  void operator init(real Tc, real QpR, real D=Tc
    , real blockHeight=0.5, real blockTop=1.5QpR, int nSections=10
    ,real xtipSize=0.5, real ytipSize=xtipSize){
    this.Tc=Tc;
    this.QpR=QpR;
    this.D=D;
    this.blockHeight=blockHeight;
    this.blockTop=blockTop;
    this.nSections=nSections;
    this.xtipSize=xtipSize;
    this.ytipSize=ytipSize;
    this.cad = sCAD.Create();
    drawGraph();
    drawBlock();
    drawAxes();
    drawYLabel();
  }
}
\end{filecontents*}
%
%
\documentclass[10pt,a4paper]{article}
\usepackage{lmodern}
\usepackage{subcaption}
\usepackage[inline]{asymptote}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
%
\begin{document}
%
\begin{figure}
\captionsetup[subfigure]{justification=centering}
    \centering
      \begin{subfigure}{0.49\textwidth}
\begin{asy}
size(7cm);
import panel;
defaultpen(fontsize(10pt));
Panel pan=Panel(3, 4,nSections=11);
\end{asy}
%
\caption{$D=T_c$}
\label{fig:1a}
\end{subfigure}
%
\begin{subfigure}{0.49\textwidth}
\begin{asy}
size(8cm);
import panel;
defaultpen(fontsize(10pt));
Panel pan=Panel(2, 5,D=6,nSections=15);
\end{asy}
%
\caption{$D>T_c$}
\label{fig:1b}
\end{subfigure}
\end{figure}
%
\end{document}

为了处理它latexmk,请创建文件latexmkrc

sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");

然后运行latexmk -pdf p.tex

答案2

以下是使用 TikZ 的可能性;定义了一些辅助命令来自动绘制图表的某些元素(见下面的解释):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains,arrows}

\newcommand\textarrow[3]{%
  \draw[<->,] #1 -- node[fill=white] {$\scriptstyle #3$} #2;}

\newcommand\myrect[3]{%
\begin{scope}[
  yshift=#2,
  start chain,
  every node/.style={on chain,inner sep=0pt,text width=2mm},
  node distance=-\pgflinewidth,anchor=west
]
\foreach \mvalue  in {1,...,\the\numexpr#1*5\relax}
   \node[draw,text height=14pt] {};
\end{scope}
\draw[<->] 
  ([yshift=#2+19pt]0,0) -- 
    node[fill=white] {$\scriptstyle#3$} 
  ([yshift=#2+19pt]#1,0);
\draw ([yshift=#2+9pt]#1,0) -- +(0,15pt);
}

\newcommand\axes[2]{%
\draw[->] (0,0) -- +(0,#1);
\draw[->] (0,0) -- +(#2,0);
}

\begin{document} 

\begin{tikzpicture}[>=latex]
\axes{7}{7}
\draw (0,0) -- (3,4) -- (6,0);
\textarrow{(3,0)}{(3,4)}{Q_pR}
\textarrow{(0,-12pt)}{(3,-12pt)}{r_c}
\textarrow{(3,-12pt)}{(6,-12pt)}{r_c}
\foreach \xcoor in {0,3,6}
  \draw (\xcoor,-2pt) -- +(0,-15pt);
\myrect{3}{5.25cm}{D-T_c}
\node[rotate=90,anchor=south,font=\small] at (0,3) {Discharge (cms)};
\node[anchor=east,font=\small] at (0,5.2) {(A)};
\end{tikzpicture}

\vspace{1cm}

\begin{tikzpicture}[>=latex]
\axes{7}{9}
\draw (0,0) -- (2,4) -- (6,4) -- (8,0);
\textarrow{(2,0)}{(2,4)}{Q_pR}
\textarrow{(0,4cm+12pt)}{(2,4cm+12pt)}{r_c}
\textarrow{(6,4cm+12pt)}{(8,4cm+12pt)}{r_c}
\foreach \xcoor in {2,6}
  \draw (\xcoor,4cm+2pt) -- +(0,15pt);
\draw (8,0) -- +(0,4cm+17pt);
\myrect{6}{5.5cm}{D}
\node[rotate=90,anchor=south,font=\small] at (0,3) {Discharge (cms)};
\node[anchor=east,font=\small] at (0,5.5) {(B)};
\end{tikzpicture}

\end{document}

在此处输入图片描述

辅助命令包括:

\axes{<length1>}{<length2>}

绘制两个垂直轴:从(0,0)(0,<lenght1>)以及从(0,0)(<length2>,0)

\myrect{<value>}{<length>}{<text>}

(0,<length>)绘制从 开始向右延伸距离 的阴影矩形<value>;它还会在矩形顶部中间放置一个箭头<text>。在其当前形式中,<value>必须为正整数。

最后,第三条命令

\textarrow{<pos1>}{<pos2>}{<text>}

<pos1>在和之间画一条线,<pos2>两端有箭头,<text>中间有 。例如,

\begin{tikzpicture}[>=latex]
\axes{5}{12}
\myrect{3}{3cm}{a}
\myrect{6}{1cm}{b}
\end{tikzpicture}

生产

在此处输入图片描述

\begin{tikzpicture}[>=latex]
\textarrow{(3.5,0)}{(3.5,3)}{a}
\textarrow{(0,0)}{(3,0)}{b}
\textarrow{(4,0)}{(6,3)}{c}
\end{tikzpicture}

生产

在此处输入图片描述

相关内容