有没有办法在 Latex 中轻松制作这样的棒图?

有没有办法在 Latex 中轻松制作这样的棒图?

我正在尝试用 Latex 创建图表,但对于我的 Tikz 经验水平来说,它太复杂了。有没有办法轻松地重新创建这个图表?或者有什么关于我应该怎么做的提示?感谢您提供的任何帮助!

我正在尝试重建的形象

答案1

由于它太宽,您可能难以将其放入页面上,但这里有一个解决方案forest

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\tikzset{circ/.style={label={[draw, circle, red, minimum size=2.5ex, inner sep=0pt]left:#1}}}

\begin{document}

\begin{forest}
for tree={math content, l*=.3, anchor=center, font=\footnotesize,
    if level>=2{l sep=1mm, if level>=3{no edge}{}}{l sep=2cm},
    s sep=4mm}
[{(A,B,C)}
    [\emptyset[\emptyset, circ=1]]
    [(A)[\{(A)\}, circ=2]]
    [(B)[\{(B)\}, circ=3]]
    [(C)[\{(C)\}, circ=4]]
    [{(A,B)}[{\{(A),(B)\}}, circ=5[{\{(A,B)\}}, circ=6]]]
    [{(A,C)}[{\{(A),(C)\}}, circ=7[{\{(A,C)\}}, circ=8]]]
    [{(B,C)}[{\{(B),(C)\}}, circ=9[{\{(B,C)\}}, circ=10]]]
    [{(A,B,C)}
        [{\{(A),(B),(C)\}}, circ=11[{\{(A,B),(C)\}}, circ=12[{\{(A,C),(B)\}}, circ=13[{\{(B,C),(A)\}}, circ=14[{\{(A,B,C)\}}, circ=15]]]]]]
]
\end{forest}

\end{document}

答案2

我已经很久没有使用没有几何图形的 TikZ 了。这里有一个经典的解决方案(Sandy 的答案很完美)我只遇到了一个问题,也许最好将 10、11、12 等对齐。我使用了 Sandy 的风格

更新红色数字的对齐方式

\documentclass[a4paper,10pt,landscape]{article}
\usepackage{tikz}
\tikzset{circ/.style={label={[draw, circle, red, minimum size=2.5ex, inner sep=0pt]left:#1}}}
\begin{document} 
\begin{tikzpicture} [font=\footnotesize,
grow=south, level 1/.style={sibling distance=6em, level distance=5cm},
level 2/.style={ level distance=2cm},
level 3/.style={ level distance=1.5em},
level 4/.style={ level distance=1.5em},
level 5/.style={ level distance=1.5em},
level 6/.style={ level distance=1.5em}]
\node {(A,B,C)} % root
    child { node {$\emptyset$}
      child { node[circ=1] {$\emptyset$}}
    }
    child { node {(A)}
      child { node[circ=2] {\{(A)\}}}
    }
    child { node {(B)}
      child { node[circ=3] {\{(B)\}}}
    }
    child { node {(C)}
      child { node[circ=4] {\{(C)\}}}
    }
    child { node {(A,B)}
      child {   node[circ=5,minimum width=1.5cm] {\{(A),(B)\}} 
        child { node[circ=6,minimum width=1.5cm] {\{(A,B)\}}}}
    }
    child { node {(A,C)}
      child { node[circ=7,minimum width=1.5cm] {\{(A),(C)\}} 
        child {node[circ=8,minimum width=1.5cm] {\{(A,C)\} }}}
    }
    child { node {(B,C)}
      child { node[circ=9,minimum width=1.5cm] {\{(B),(C)\}} 
        child {node[circ=10,minimum width=1.5cm] {\{(B,C)\}}}}
    }
    child { node {(A,B,C)}
      child { node[circ=11,minimum width=2cm] {\{(A),(B),(C)\}} 
        child {node[circ=12,minimum width=2cm] {\{(A,B),(C)\}}  
         child {node[circ=13,minimum width=2cm] {\{(A,C),(B)\}} 
           child {node[circ=14,minimum width=2cm] {\{(B,C),(A)\}} 
             child {node[circ=15,minimum width=2cm] {\{(A,B,C)\}}}}}}}
};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

我建议使用马查。在那里,您可以通过选择“插入图表”选项并选择“绘图区域”选项来绘制,以在右侧显示绘图区域。我正在分享与您的图表类似的代码。您可以使用此平台将您的作品导出为图像或 TikZ 格式。我建议选择 TikZ 选项以获得更好的质量。

\documentclass{article}

\usepackage{tikz}

\begin{document}

\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,296); %set diagram left start at 0, and has height of 296

%Straight Lines [id:da842538810449589] 
\draw    (381.88,44.88) -- (353.08,112.48) ;
%Straight Lines [id:da7257564806335599] 
\draw    (434.88,130.36) -- (434.88,179.56) ;
%Straight Lines [id:da20949947181562223] 
\draw    (349.88,130.36) -- (349.88,179.56) ;
%Straight Lines [id:da2593651135736319] 
\draw    (518.68,130.16) -- (518.68,179.36) ;
%Straight Lines [id:da7741353868078296] 
\draw    (281.88,131.36) -- (281.88,180.56) ;
%Straight Lines [id:da9720425366631544] 
\draw    (227.88,130.96) -- (227.88,180.16) ;
%Straight Lines [id:da581739553085237] 
\draw    (173.88,131.36) -- (173.88,180.56) ;
%Straight Lines [id:da8464131628402256] 
\draw    (120.68,130.56) -- (120.68,179.76) ;
%Straight Lines [id:da058139682734349885] 
\draw    (614.48,129.76) -- (614.48,178.96) ;
%Straight Lines [id:da4017264009317001] 
\draw    (177.4,111.13) -- (356.28,44.88) ;
%Straight Lines [id:da7610123999802281] 
\draw    (229.72,110.88) -- (365.88,44.88) ;
%Straight Lines [id:da2905799653222627] 
\draw    (123.32,112.48) -- (352.6,40.67) ;
%Straight Lines [id:da9847257278990789] 
\draw    (283.88,110.08) -- (374.68,44.88) ;
%Straight Lines [id:da09133555586008946] 
\draw    (389.48,44.88) -- (435.48,110.88) ;
%Straight Lines [id:da06694033598480398] 
\draw    (397.88,44.48) -- (518.33,110.53) ;
%Straight Lines [id:da5575718778158445] 
\draw    (408.28,43.68) -- (612.68,110.48) ;

% Text Node
\draw (351.4,24.4) node [anchor=north west][inner sep=0.75pt]    {$( A,B,C)$};
% Text Node
\draw (269.87,112.2) node [anchor=north west][inner sep=0.75pt]    {$( C)$};
% Text Node
\draw (329.67,112.07) node [anchor=north west][inner sep=0.75pt]    {$( A,B)$};
% Text Node
\draw (413.2,112.2) node [anchor=north west][inner sep=0.75pt]    {$( A,C)$};
% Text Node
\draw (262.48,182.68) node [anchor=north west][inner sep=0.75pt]    {$\{( C)\}$};
% Text Node
\draw (316.48,182.28) node [anchor=north west][inner sep=0.75pt]    {$\{( A) ,( B)\}$};
% Text Node
\draw (317.28,202.08) node [anchor=north west][inner sep=0.75pt]    {$\{( A,B)\}$};
% Text Node
\draw (400.68,182.68) node [anchor=north west][inner sep=0.75pt]    {$\{( A) ,( C)\}$};
% Text Node
\draw (401.08,202.28) node [anchor=north west][inner sep=0.75pt]    {$\{( A,C)\}$};
% Text Node
\draw (498.47,111.87) node [anchor=north west][inner sep=0.75pt]    {$( B,C)$};
% Text Node
\draw (485.28,182.08) node [anchor=north west][inner sep=0.75pt]    {$\{( B) ,( C)\}$};
% Text Node
\draw (485.08,201.88) node [anchor=north west][inner sep=0.75pt]    {$\{( B,C)\}$};
% Text Node
\draw (215.87,111.8) node [anchor=north west][inner sep=0.75pt]    {$( B)$};
% Text Node
\draw (208.48,182.28) node [anchor=north west][inner sep=0.75pt]    {$\{( B)\}$};
% Text Node
\draw (161.87,112.2) node [anchor=north west][inner sep=0.75pt]    {$( A)$};
% Text Node
\draw (154.48,182.68) node [anchor=north west][inner sep=0.75pt]    {$\{( A)\}$};
% Text Node
\draw (114.27,111.8) node [anchor=north west][inner sep=0.75pt]    {$\emptyset $};
% Text Node
\draw (113.87,182.2) node [anchor=north west][inner sep=0.75pt]    {$\emptyset $};
% Text Node
\draw (581.2,111) node [anchor=north west][inner sep=0.75pt]    {$( A,B,C)$};
% Text Node
\draw (568.68,181.48) node [anchor=north west][inner sep=0.75pt]    {$\{( A) ,( B) ,( C)\}$};
% Text Node
\draw (569.08,202.08) node [anchor=north west][inner sep=0.75pt]    {$\{( A,B) ,( C)\}$};
% Text Node
\draw (569.08,221.88) node [anchor=north west][inner sep=0.75pt]    {$\{( A,C) ,( B)\}$};
% Text Node
\draw (568.88,241.88) node [anchor=north west][inner sep=0.75pt]    {$\{( B,C) ,( A)\}$};
% Text Node
\draw (569.21,261.81) node [anchor=north west][inner sep=0.75pt]    {$\{( A,B,C)\}$};
% Text Node
\draw (32,174.33) node [anchor=north west][inner sep=0.75pt]   [align=left] {\begin{minipage}[lt]{44.12pt}\setlength\topsep{0pt}
\begin{center}
Possible \\Groups
\end{center}

\end{minipage}};
% Text Node
\draw (14.67,100) node [anchor=north west][inner sep=0.75pt]   [align=left] {\begin{minipage}[lt]{58.85pt}\setlength\topsep{0pt}
\begin{center}
Participating\\Schools
\end{center}

\end{minipage}};
% Text Node
\draw (206.07,16.4) node [anchor=north west][inner sep=0.75pt]   [align=left] {\begin{minipage}[lt]{49.78pt}\setlength\topsep{0pt}
\begin{center}
Schools in\\District
\end{center}

\end{minipage}};

\end{tikzpicture}
\end{document}

当您使用上述代码时,您将获得以下结果。

在此处输入图片描述

相关内容