TeX - LaTeX Asked on April 24, 2021
I wish to reduce the width between the children in a tree.
Look at the image given below:
The right child of F is getting hidden due to left child negation(r).This is how my latex file looks like as of now
documentclass[12pt,letterpaper]{article}
usepackage[margin = 1in]{geometry}
usepackage{amsmath}
usepackage{amssymb}
usepackage{fancyhdr}
usepackage{tikz}
usetikzlibrary{trees}
begin{document}
begin{center}
begin{tikzpicture}[sibling distance=10em,
every node/.style = {
shape=rectangle,
rounded corners,
draw,
align=center,
top color=white,
bottom color=blue!5}]]
node {$varnothing$}
child{node {F}
child{node {$lnot$p}
child{node {$lnot$p$lor$ q}}
child{node {$lnot$q}}
}
child{node {p}}
}
child{node {$lnot$r}
child{node {$lnot$r$lor$ s}}
child{node {$lnot$s}}
}
child{node {r}};
end{tikzpicture}
end{center}
end{document}
How do I fix this issue?Thanks in advance!
The basic answer to your tree problem is don't use the base TikZ tree methods. Their syntax is clunky and it does no automatic positioning of nodes (as you have discovered.) Instead use forest
for making trees. It has a much simpler syntax and does automatic packing of nodes to make trees as compact as possible, but allows you to make them less compact as needed.
But there are many other mistakes in the code you've shown us. It seems like you need to read a good basic introduction of how to use LaTeX more generally. Here are some things I've noticed and fixed (there may be others I've missed.) For a list of common mistakes beginners make see What are the most common mistakes that beginners of (La)TeX and Friends make?. See also What are good learning resources for a LaTeX beginner? and especially the new https://www.learnlatex.org/ site.
subsection
commands.itemize
environment using the enumitem
package to format the items.[ ... ]
not begin{center} ... end{center}
. And in LaTeX you should never use $$ ... $$
to introduce displayed math. See Why is [ ... ] preferable to $$ ... $$? and also What are the differences between $$, [, align, equation and displaymath? for more options.
to end a paragraph, and in running text you should generally not use it at all. See When to use par and when , newline, or blank lines.documentclass[12pt,letterpaper]{article}
usepackage[margin = 1in]{geometry}
usepackage{amsmath}
usepackage{amssymb}
usepackage{fancyhdr}
usepackage{enumitem}
usepackage[small]{titlesec}
usepackage{tikz}
usepackage[linguistics]{forest}
forestset{mynode/.style={ shape=rectangle,
rounded corners,
draw,
align=center,
top color=white,
bottom color=blue!5,
math content}}
author{emph{Muppuri Siva Jagadesh}}
title{textbf{Discrete Maths}}
pagestyle{fancy}
renewcommand{headrulewidth}{0pt}
renewcommand{footrulewidth}{0pt}
fancyhf{}
rhead{
Assignment 1
}
rfoot{Page thepage}
begin{document}
maketitle
section{LECTURE 1: SAT PROBLEM}
subsection{What will we learn?}
begin{itemize}[label=$rightarrow$]
item Satifiability
item Conjunctive Normal Forms
end{itemize}
subsection{Satisfiability}
A compound proposition is satisfiable if it is true for at least one truth assignment of the underlying propositional variables.
[
text{e.g.: } (p lor lnot q) land (q lor lnot r)
]
subsection{}
begin{enumerate}
item Replace all $Leftrightarrow$ symbol (if any)
[
(p Leftrightarrow q) equiv (p rightarrow q) land (q rightarrow p)
]
item [sum_{n=1}^{infty} 2^{-n} = 1]
end{enumerate}
subsection{}
begin{forest}for tree={mynode, s sep=1cm}
[varnothing
[F
[lnot p
[lnot p lor q ]
[lnot q ]
]
[p ]
]
[lnot r
[lnot r lor s ]
[lnot s ]
]
[r]
]
end{forest}
end{document}
Correct answer by Alan Munn on April 24, 2021
You should only place here the code necessary for your question, personal information and code that does not relate to your problem should not be placed in the question.
Here, it is enough to adjust the distance between the children with the level 1
and level 2
style.
level 1/.style={sibling distance=10em},
level 2/.style={sibling distance=5em},
documentclass[border=5mm]{standalone}
usepackage{amssymb}
usepackage{tikz}
usetikzlibrary{trees}
begin{document}
begin{tikzpicture}[%sibling distance=10em,
level 1/.style={sibling distance=10em},
level 2/.style={sibling distance=5em},
every node/.style = {
shape=rectangle,
rounded corners,
draw,
align=center,
top color=white,
bottom color=blue!5}]]
node {$varnothing$}
child{node {F}
child{node {$lnot$p}
child{node {$lnot$p$lor$ q}}
child{node {$lnot$q}}
}
child{node {p}}
}
child{node {$lnot$r}
child{node {$lnot$r$lor$ s}}
child{node {$lnot$s}}
}
child{node {r}};
end{tikzpicture}
end{document}
Answered by AndréC on April 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP