How to make the tree-like graph in Latex? - latex

I need to use LaTeX to create the following graph. I am just completely stuck with no idea how to get started. It seems there are some packages like TikZ that I could use to plot tree type of images, however I could not find anything to my example.
Notice that some of those are arrows, while some are just line segments. And most examples I found are vertical structure, but this one is horizontal.
Any tips would be appreciated.

To provide my best suggestion I used trees library from TikZ.
The code:
\documentclass[tikz,margin=2mm]{standalone}
\usetikzlibrary{trees,arrows}
\begin{document}
\tikzstyle{level 1}=[level distance=30mm, sibling distance=30mm]
\tikzstyle{level 2}=[level distance=30mm, sibling distance=15mm]
\tikzstyle{level 3}=[level distance=20mm]
\begin{tikzpicture}[grow=right,->,>=angle 60]
%\begin{scope}[yshift=0]
\node {$A_{1,1}$}
child {node {$A_{2,2}$}
child {node {$A_{3,2}$}
child[-] {node{$S^{<4>}$}}
}
child {node{$A_{3,1}$}
child[-] {node{$S^{<3>}$}}
}
}
child {node {$A_{2,1}$}
child {node{$A_{3,2}$}
child[-] {node{$S^{<2>}$}}
}
child {node{$A_{3,1}$}
child[-] {node{$S^{<1>}$}}
}
};
%\end{scope}
\begin{scope}[yshift=-6cm]
\node {$A_{1,2}$}
child {node {$A_{2,2}$}
child {node {$A_{3,2}$}
child[-] {node{$S^{<8>}$}}
}
child {node {$A_{3,1}$}
child[-] {node{$S^{<7>}$}}
}
}
child {node {$A_{2,1}$}
child {node {$A_{3,2}$}
child[-] {node{$S^{<6>}$}}
}
child {node {$A_{3,1}$}
child[-] {node{$S^{<5>}$}}
}
};
\end{scope}
\end{tikzpicture}
\end{document}
And the output, very similar to yours.
Notice how no arrows at level 3 are provided by the syntax child[-] instead of child (default is ->,>=angle 60).

Related

How can I make more space between node and edge in Latex Tree Diagram?

I want "Child" at the left to fit in better like the rest and I want more space at the right side between the last nodes and the calculations P(x) = 1/2
this is the code:
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
%document already started
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3cm, sibling distance=2cm]
\tikzstyle{level 2}=[level distance=3cm, sibling distance=1cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=1em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right]
\node[bag] {Child}
child {
node[bag] {G}
child {
node[end, label=right:
{G $P(G\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {0.5}
}
child {
node[end, label=right:
{B $P(G\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[below] {$0.5$}
}
child {
node[bag] {B}
child {
node[end, label=right:
{G $P(B\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {$0.5$}
}
child {
node[end, label=right:
{B $P(B\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[above] {$0.5$}
};
\end{tikzpicture}
%end of document
I don't know hat I can do. I have tried to change the width which is 1em right now. But if I increase it the diagram gets even more out of shape and if I decrease it it completely covers "Child"
I have tried to make more spaces behind the last event (before the P(blabla) thing). But that didn't chnage anything.
repetitive spaces in latex are treated like a single space. If you'd like to manually increase the space, you could e.g. use \qquad
to avoid your Child node from colliding with the lines, you can increase its text width. This will move it a bit further away from the lines
don't use \tikzstyle, this macro is obsolete.
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
% Set the overall layout of the tree
\tikzset{level 1/.style={level distance=3cm, sibling distance=2cm}}
\tikzset{level 2/.style={level distance=3cm, sibling distance=1cm}}
% Define styles for bags and leafs
\tikzset{bag/.style={text width=1em, text centered}}
\tikzset{end/.style={circle, minimum width=3pt,fill, inner sep=0pt}}
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right]
\node[bag,minimum width=2cm] {Child}
child {
node[bag] {G}
child {
node[end, label=right:
{G\qquad$P(G\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {0.5}
}
child {
node[end, label=right:
{B\qquad $P(G\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[below] {$0.5$}
}
child {
node[bag] {B}
child {
node[end, label=right:
{G\qquad $P(B\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {$0.5$}
}
child {
node[end, label=right:
{B\qquad $P(B\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[above] {$0.5$}
};
\end{tikzpicture}
\end{document}

hdashline with starting and ending markers latex

Can we have use hdashline with starting and ending markers? Something like
<---------->
One possibility is to use tikz:
\documentclass{article}
\usepackage{tikz}
\begin{document}
some text
\noindent\tikz{\draw[<->,dashed] (0,0) -- (\textwidth-0.4pt,0);}
some text
\end{document}
If you need this in a table, you can use the nicematrix package (inspired by this answer https://tex.stackexchange.com/a/635224/36296 )
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\NiceMatrixOptions
{
custom-line =
{
command = arrowrule ,
tikz = { dashed, <-> }
}
}
\begin{NiceTabular}{XX}
some & text\\
\arrowrule
some & text\\
\end{NiceTabular}
\end{document}

Create side-by-side environments in Latex

I am trying to create three environments that are beside one another and do not fill the entire page as seen in the attached image. Within each environment, I am trying to add the cvref function, attached is the necessary cls code.
test.cls
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\#ifl#t#r\fmtversion{2018/04/01}{\UseRawInputEncoding}{}
\ProvidesClass{altacv}[2018/07/27 AltaCV v1.1.4, yet another alternative class for a résumé/curriculum vitae.]
\newif\if#academicons
\DeclareOption{academicons}{\#academiconstrue}
%% v1.1.3: Choice of round/square photo
\newif\if#normalphoto
\DeclareOption{normalphoto}{\#normalphototrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}}
\ProcessOptions\relax
\LoadClass{extarticle}
\RequirePackage[margin=2cm]{geometry}
\RequirePackage{fontawesome}
%% v1.1: Optionally load academicons
\if#academicons
%% Patch to make academicons compilable with XeLaTeX
\ExplSyntaxOn
\msg_redirect_name:nnn { fontspec } { font-not-found } { none }
\ExplSyntaxOff
\RequirePackage{academicons}
\newfontfamily{\AI}{academicons.ttf}
\fi
\RequirePackage{xcolor}
\colorlet{accent}{blue!70!black}
\colorlet{heading}{black}
\colorlet{emphasis}{black}
\colorlet{body}{black!80!white}
\newcommand{\itemmarker}{{\small\textbullet}}
\newcommand{\ratingmarker}{\faCircle}
\RequirePackage{tikz}
\usetikzlibrary{arrows}
\RequirePackage[skins]{tcolorbox}
\RequirePackage{enumitem}
\setlist{leftmargin=*,labelsep=0.5em,nosep,itemsep=0.25\baselineskip,after=\vskip0.25\baselineskip}
\setlist[itemize]{label=\itemmarker}
\RequirePackage{graphicx}
\RequirePackage{etoolbox}
\RequirePackage{dashrule}
\RequirePackage{multirow,tabularx}
\RequirePackage{changepage}
% \RequirePackage{marginfix}
\setlength{\parindent}{0pt}
\newcommand{\divider}{\textcolor{body!30}{\hdashrule{\linewidth}{0.6pt}{0.5ex}}\medskip}
\newenvironment{fullwidth}{%
\begin{adjustwidth}{}{\dimexpr-\marginparwidth-\marginparsep\relax}}
{\end{adjustwidth}}
\newcommand{\emailsymbol}{\faAt}
\newcommand{\phonesymbol}{\faPhone}
\newcommand{\homepagesymbol}{\faChain}
\newcommand{\locationsymbol}{\faMapMarker}
\newcommand{\linkedinsymbol}{\faLinkedin}
\newcommand{\twittersymbol}{\faTwitter}
\newcommand{\githubsymbol}{\faGithub}
\newcommand{\orcidsymbol}{\aiOrcid}
\newcommand{\mailsymbol}{\faEnvelope}
\newcommand{\printinfo}[2]{\mbox{\textcolor{accent}{\normalfont #1}\hspace{0.5em}#2\hspace{2em}}}
\newcommand{\weblinks}[3]{\mbox{\textcolor{accent}{\normalfont #1}\hspace{0.5em}{\href{#2}{#3}}\hspace{2em}}}
\newcommand{\name}[1]{\def\#name{#1}}
\newcommand{\tagline}[1]{\def\#tagline{#1}}
\newcommand{\photo}[2]{\def\#photo{#2}\def\#photodiameter{#1}}
\newcommand{\email}[2]{\weblinks{\emailsymbol}{#1}{#2}}
\newcommand{\mailaddress}[1]{\printinfo{\mailsymbol}{#1}}
\newcommand{\phone}[1]{\printinfo{\phonesymbol}{#1}}
\newcommand{\homepage}[2]{\weblinks{\homepagesymbol}{#1}{#2}}
\newcommand{\twitter}[1]{\printinfo{\twittersymbol}{#1}}
\newcommand{\linkedin}[2]{\weblinks{\linkedinsymbol}{#1}{#2}}
\newcommand{\github}[2]{\weblinks{\githubsymbol}{#1}{#2}}
\newcommand{\orcid}[1]{\printinfo{\orcidsymbol}{#1}}
\newcommand{\location}[1]{\printinfo{\locationsymbol}{#1}}
\newcommand{\cvsection}[2][]{%
\bigskip%
\ifstrequal{#1}{}{}{\marginpar{\vspace*{\dimexpr1pt-\baselineskip}\raggedright\input{#1}}}%
{\color{heading}\LARGE\bfseries\MakeUppercase{#2}}\\[-1ex]%
{\color{heading}\rule{\linewidth}{2pt}\par}\medskip
}
\newcommand{\cvref}[4]{%
\smallskip
\textcolor{emphasis}{\textbf{#1}}\par
\smallskip\normalsize
\ifstrequal{#2}{}{}{
\textbf{\color{accent}#2}\par
\smallskip}
\begin{description}[font=\color{accent},style=multiline,leftmargin=1.25em]
\item[\small\normalfont\mailsymbol] #3
\item[\small\normalfont\phonesymbol] #4
\end{description}
\medskip
% \medskip
}
\newenvironment{cvcolumn}[1]{\begin{minipage}[t]{#1}\raggedright}{\end{minipage}}
\RequirePackage[backend=biber,style=authoryear,sorting=ydnt]{biblatex}
%% For removing numbering entirely when using a numeric style
% \setlength{\bibhang}{1em}
% \DeclareFieldFormat{labelnumberwidth}{\makebox[\bibhang][l]{\itemmarker}}
% \setlength{\biblabelsep}{0pt}
\defbibheading{pubtype}{\cvsubsection{#1}}
\renewcommand{\bibsetup}{\vspace*{-\baselineskip}}
\AtEveryBibitem{\makebox[\bibhang][l]{\itemmarker}}
\setlength{\bibitemsep}{0.25\baselineskip}
% v1.1.2: make it easier to add a sidebar aligned with top of next page
\RequirePackage{afterpage}
\newcommand{\addsidebar}[2][]{\marginpar{%
\ifstrequal{#1}{}{}{\vspace*{#1}}%
\input{#2}}%
}
\newcommand{\addnextpagesidebar}[2][]{\afterpage{\addsidebar[#1]{#2}}}
\AtBeginDocument{%
\pagestyle{empty}
\color{body}
\raggedright
}
It is called in the following snippet:
test.tex
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[10pt,letterpaper]{altacv}
\geometry{left=1cm,right=9cm,marginparwidth=6.8cm,marginparsep=1.2cm,top=1.25cm,bottom=1.25cm,footskip=2\baselineskip}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}
\definecolor{Mulberry}{HTML}{72243D}
\definecolor{SlateGrey}{HTML}{2E2E2E}
\definecolor{LightGrey}{HTML}{666666}
\colorlet{heading}{Sepia}
\colorlet{accent}{Mulberry}
\colorlet{emphasis}{SlateGrey}
\colorlet{body}{LightGrey}
\renewcommand{\itemmarker}{{\small\textbullet}}
\renewcommand{\ratingmarker}{\faCircle}
\usepackage[hidelinks]{hyperref}
\begin{document}
\begin{fullwidth}
\cvsection{References}
\begin{minipage}[t]{0.5\textwidth}
\begin{flushleft}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{flushleft}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{center}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{center}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{flushright}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{flushright}
\end{minipage}
\end{fullwidth}
\medskip
\end{document}
Any guidance would be greatly appreciated. I tried a tabular environment, but it won't let me use the cvref function within the cells.
Using minipages, I get the following result:
your fullwidth environment does not adjust the \textwidth. However you can use .33\linewidth to automatically get the width of the minipages
the cvref macro internally used a description, that's why it does not obey your attempts to center or left align. You can use the following redefinition to get a similar result, which will obey your alignment:
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[10pt,letterpaper]{test}
\geometry{left=1cm,right=9cm,marginparwidth=6.8cm,marginparsep=1.2cm,top=1.25cm,bottom=1.25cm,footskip=2\baselineskip}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[default]{lato}
\definecolor{Mulberry}{HTML}{72243D}
\definecolor{SlateGrey}{HTML}{2E2E2E}
\definecolor{LightGrey}{HTML}{666666}
\colorlet{heading}{Sepia}
\colorlet{accent}{Mulberry}
\colorlet{emphasis}{SlateGrey}
\colorlet{body}{LightGrey}
\renewcommand{\itemmarker}{{\small\textbullet}}
\renewcommand{\ratingmarker}{\faCircle}
\usepackage[hidelinks]{hyperref}
\renewcommand{\cvref}[4]{%
\smallskip
\textcolor{emphasis}{\textbf{#1}}\par
\smallskip\normalsize
\ifstrequal{#2}{}{}{
\textbf{\color{accent}#2}\par
\smallskip}
% \begin{description}[font=\color{accent},style=multiline,leftmargin=1.25em]
{\color{accent}\small\normalfont\mailsymbol} #3\par
{\color{accent}\small\normalfont\phonesymbol} #4\par
% \end{description}
\medskip
% \medskip
}
\begin{document}
\begin{fullwidth}
\cvsection{References}
\begin{minipage}[t]{0.3\linewidth}
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\centering
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\begin{minipage}[t]{0.3\linewidth}
\raggedleft
\cvref{test}{test}{\href {mailto:test}{test}}{test}
\end{minipage}
\end{fullwidth}
\end{document}

Using directlua command inside tikzpicture (pgf-pie) causes image not to render

Using \directlua command inside tikzpicture (pgf-pie) causes image not to render:
\documentclass[margin=5mm,preview]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture} % works
\pie[radius=2, rotate=100, sum=auto]
{
3/test , 2/two , 3/three , 4/four
}
\end{tikzpicture}
\begin{tikzpicture} % does not work
\pie[radius=2, rotate=100, sum=auto]
{
\directlua{tex.sprint("3/test , 2/two , 3/three , 4/four")}
}
\end{tikzpicture}
\end{document}
The result can be view here
How gets \directlua expanded? And what do I need to change to create tikzpicture pie charts with variables from lua?

TikZ Mindmap: text in the nodes undesirably covered by connectors

I created a mindmap (see below). I found my text was undesirably covered by the connectors. Is there a way to put the connector a layer below the text, or put the text a layer above the connector? I know I can bypass this problem by changing the node size, or the font size, or the sibling angle. But I prefer the current appearance so I don't want to change any of the parameters above. I just want to change the layers. Is there a way to do so?
\documentclass[12pt,twoside]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[mindmap, grow cyclic, every node/.style=concept, concept color=green!80,
level 1/.append style={level distance=5cm, sibling angle=180},
level 2/.append style={level distance=3cm, sibling angle=90}]
\node{Gram positive bacteria}
child[concept color=orange!80]{ node{Firmicutes}
child{node{\textit{Listeria}}
}
child{node{\textit{Bacillus}}
}
child{node{\textit{Streptococcus}}
}
child{node{\textit{Enterococcus}}
}
}
child[concept color=purple!30,]{ node{Actinobacteria}
child{node{\textit{Streptomyces}}
}
child{node{\textit{Corynebacterium}}
}
child{node{\textit{Mycobacterium}}
}
}
;
\end{tikzpicture}
\end{document}
One cheap hack to bypass the problem described in your title is to manually hyphen text locally, where necessary. In your case, you could change lines 27 (for the sake of consistency), 30 and 32 of your code respectively to:
child[concept color=purple!30]{node{Actino\-bacteria}
...
child{node{\textit{Coryne\-bacterium}}
...
child{node{\textit{Myco\-bacterium}}
I used an extra node (mycobacterium) to write the text after the mindmap has been rendered.
\begin{tikzpicture}[mindmap, grow cyclic, every node/.style=concept, concept color=green!80,
level 1/.append style={level distance=5cm, sibling angle=180},
level 2/.append style={level distance=3cm, sibling angle=90}]
\node{Gram positive bacteria}
child[concept color=orange!80]{ node{Firmicutes}
child{node{\textit{Listeria}}
}
child{node{\textit{Bacillus}}
}
child{node{\textit{Streptococcus}}
}
child{node{\textit{Enterococcus}}
}
}
child[concept color=purple!30,]{ node{Actinobacteria}
child{node{\textit{Streptomyces}}
}
child{node{\textit{Corynebacterium}}
}
child{node (mycobacterium) {}
}
};
\node[extra concept,fill=none,draw=none] at (mycobacterium) {\textit{Mycobacterium}};
\end{tikzpicture}

Resources