我想在 latex 中绘制下图。但我对 latex 图表还不熟悉。有人能给我提示吗?

我想在 latex 中绘制下图。但我对 latex 图表还不熟悉。有人能给我提示吗?

我刚刚加入社区,不知道如何绘制这样的图表。但如果有人开始编写代码,我就可以毫无问题地编写数学公式。 在此处输入图片描述

答案1

您的图像让我想起了树,所以让我们看看如何借助包来绘制它forest

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
                quotes}
\tikzset{
       every edge/.style = {draw, -Stealth, semithick, shorten >=2mm, shorten <=2mm},
every edge quotes/.style = {auto=right, pos=0.55, inner sep=2pt},
  dotsnode/.append style = {draw=none, text width=2em, node contents={\\$\dots$}}
    }
\newcommand\sfbf[1]{\textsf{\textbf{#1}}}

\begin{document}
\setlength\fboxsep{1ex}
\fbox{
    \begin{forest}
for tree = {draw, rounded corners, thick,
            where level = {0}{text width=8em}{text width=7em},
            text centered,
            font=\sffamily,
            edge={draw=none},
% 
             s sep =  3mm,
             l sep = 12mm
             }
[\sfbf{RETAILER} Minimize {$f(\pi,l_1,l_2, \dots, l_n)$}, name=r
    [\sfbf{CONSUMER 1}\\ Minimize\\ $g^1_{\pi} (l_1)$, name=c1]
    [\sfbf{CONSUMER 2}\\ Minimize\\ $g^2_{\pi} (l_2)$, name=c2]    
    [,dotsnode]
    [\sfbf{CONSUMER n}\\ Minimize\\ $g^n_{\pi} (l_2)$, name=cn]
]
\path   (r) edge ["$\pi$"]  ([xshift= 2em] c1.north)
        (r) edge ["$\pi$"]  (c2)
        (r) edge ["$\pi$"]  ([xshift=-2em] cn.north);
\path[dashed, transform canvas={xshift=2mm}]   
        ([xshift= 2em] c1.north) edge ["$l_1$"] (r)
        (c2)                     edge ["$l_2$"] (r)
        ([xshift=-2em] cn.north) edge ["$l_n$"] (r);
    \end{forest}
\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta,calc,positioning, shapes.geometric}

\tikzstyle{cloud} = [ellipse, draw, fill=red!20, text centered, minimum 
width=50pt, minimum height=25pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text 
centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{document}

        \begin{tikzpicture}[
                arr/.style = {line width=2pt,red!50!black, ->, >=Stealth},
                arrd/.style = {line width=2pt,blue!50!black,dashed,->,  >=Stealth},
                block/.style = {rectangle, draw=blue!70!black, fill=blue!20, text width=8em, text 
                centered, rounded corners, minimum height=8em,font=\bfseries,inner sep=1em, outer sep=1em}
            ]

\node[block] (f1)  {RETAILER};
\node[block, below left=4cm of f1] (f2) {CONSUMER 1};
\node[block, right=of f2] (f3) {CONSUMER 2};
\node[right=of f3] (f4) {$\ldots$};
\node[block, right=of f4] (f5) {CONSUMER n};

\draw[arr]($(f1.south)+(-4em,0pt)$)to  node [font=\Large,above,black]{$\pi$} (f2.north);            
\draw[arrd]($(f2.north)+(1em,0pt)$)to  node [font=\Large,below, black]{$l_1$}($(f1.south)+(-3em,0pt)$);         

\draw[arr]($(f1.south)+(-1em,0pt)$)to node [font=\Large,left,black]{$\pi$}(f3.north);           
\draw[arrd]($(f3.north)+(1em,0pt)$)to node [font=\Large,right, black,pos=0.4]{$l_2$}($(f1.south)+(-0em,0pt)$);  

\draw[arr]($(f1.south)+(2em,0pt)$)to node [font=\Large,below, black]{$\pi$}(f5.north);          
\draw[arrd]($(f5.north)+(1em,0pt)$)to node [font=\Large,above, black, pos=0.4]{$l_n$}($(f1.south)+(3em,0pt)$);                  
\end{tikzpicture}
\end{document}

编辑两列

封闭在图形环境中——现在可以给出标题

通过使用减小尺寸\resizebox{0.5\textwidth}{!}

第一个参数0.5\textwidth是宽度, !按比例缩放。

在此处输入图片描述

梅威韋——

\documentclass[twocolumn]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta,calc,positioning, shapes.geometric,fit}

\tikzstyle{cloud} = [ellipse, draw, fill=red!20, text centered, minimum 
width=50pt, minimum height=25pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text 
centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{document}
    \lipsum
    \begin{figure}[h]
    
    
    \resizebox{0.5\textwidth}{!}{
    \sffamily\begin{tikzpicture}[
        arr/.style = {line width=2pt,red!50!black, ->, >=Stealth},
        arrd/.style = {line width=2pt,blue!50!black,dashed,->,  >=Stealth},
        block/.style = {rectangle, draw=blue!70!black, fill=blue!20, text width=8em, text 
            centered, rounded corners, minimum height=8em,font=\bfseries,inner sep=1em, outer sep=1em}
        ]
        
        \node[block] (f1)  {RETAILER};
        \node[block, below left=4cm of f1] (f2) {CONSUMER 1};
        \node[block, right=of f2] (f3) {CONSUMER 2};
        \node[right=of f3] (f4) {$\ldots$};
        \node[block, right=of f4] (f5) {CONSUMER n};
        
        \draw[arr]($(f1.south)+(-4em,0pt)$)to  node [font=\Large,above,black]{$\pi$} (f2.north);            
        \draw[arrd]($(f2.north)+(1em,0pt)$)to  node [font=\Large,below, black]{$l_1$}($(f1.south)+(-3em,0pt)$);         
        
        \draw[arr]($(f1.south)+(-1em,0pt)$)to node [font=\Large,left,black]{$\pi$}(f3.north);           
        \draw[arrd]($(f3.north)+(1em,0pt)$)to node [font=\Large,right, black,pos=0.4]{$l_2$}($(f1.south)+(-0em,0pt)$);  
        
        \draw[arr]($(f1.south)+(2em,0pt)$)to node [font=\Large,below, black]{$\pi$}(f5.north);          
        \draw[arrd]($(f5.north)+(1em,0pt)$)to node [font=\Large,above, black, pos=0.4]{$l_n$}($(f1.south)+(3em,0pt)$);    
        
        \tikzset{blue dotted/.style={draw=blue!50!white, line width=1pt,
                dash pattern=on 1pt off 4pt on 6pt off 4pt,
                inner sep=4mm, rectangle, rounded corners}};
        
        % Finally the blue dotted boxes are drawn as nodes fitted to other nodes
        \node (box) [blue dotted, 
        fit = (f1) (f2) (f3) (f4) (f5)] {};              
    \end{tikzpicture}}\caption{Sales Pattern}
\end{figure}
\lipsum
\end{document}

相关内容