您能帮我把孙子和曾孙放在图表中间吗?我该怎么做?我还注意到,当我尝试添加第四个孙子或孩子时,图表不适合一页?有没有命令可以让所有内容适合并居中?
\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,subcaption, color,setspace,sectsty,comment,footmisc,caption,natbib,pdflscape,subfigure,array, enumerate, natbib, indentfirst, float, tikz, rotating, lipsum, adjustbox, booktabs, multirow, soul, changepage,threeparttable}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup{colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=black, plainpages=false, pdfpagelabels=true, urlcolor=blue}
\usepackage[nameinlink, capitalise, noabbrev]{cleveref}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands
\normalem
\onehalfspacing
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}{Proposition}
\newtheorem{conj}{Conjecture}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand{\thesubhyp}{\thehyp\alph{subhyp}}
\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}
\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\newcommand{\FixedLengthArrow}{2,0}
\begin{document}
\tikzset{%
block/.style = {rectangle, draw, fill=yellow, text width=5em, text centered, rounded corners, minimum height=2em},
line/.style = {draw, -latex'},
}
\tikzset{
basic/.style={
draw,
text width=3cm,
drop shadow,
font=\sffamily
},
root/.style={
basic,
rounded corners=2pt,
thin,
align=center,
fill=green!30
},
child node/.style={
basic,
rounded corners=6pt,
thin,
align=center,
fill=green!60,
text width=10em,
anchor=north
},
every child node/.style={child node}
}
\begin{figure}[H]
\centering
\begin{tikzpicture}[
sibling distance=6cm,
edge from parent/.append style={->},
growth parent anchor=south,
>=Latex,
nodes={draw, fill=cyan,
text width=4cm,
text centered}
]
% root of the the initial tree, level 1
\node (root) {Oil Wealth}
% The first level, as children of the initial tree
child {node (A1) {Grandparent}
child {node (B1) {Parent}
child {node (C11) {Child}}
child {node (C12) {Child}}
child {node (C13) {Child}}}}
child {node (D11) {Grandchild}}
child {node (D12) {Grandchild}}
child {node (E12) {Grand-Grandchild}}
;
\draw [->] (C11) -- (D11);
\draw [->] (C12) -- (D11);
\draw [->] (C11) -- (D12);
\draw [->] (C12) -- (D12);
\end{tikzpicture}
\caption{Mine Editing Tex III}
\label{fig: Causal}
\end{figure}
\end{document} ````
答案1
- 请提供 MWE(最小工作示例),一个小但完整的文档,以 `\end{document} 开头
\documentclass[...]{...}
和结尾,并在序言中加载仅有的与您的问题相关的包和定义的新命令或环境。 - 尽量避免使用
[H]
浮动位置放置。这会阻止浮动浮动(它们会失去最重要的功能)。因此,这通常会导致(非常)糟糕的排版。最好使用[htb]
原始答案:
如果我正确理解了您的要求,那么以下tikz
解决方案就是您所要求的:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\begin{document}
\tikzset{%
block/.style = {rectangle, draw, fill=yellow, text width=5em, text centered, rounded corners, minimum height=2em},
line/.style = {draw, -latex'},
}
\tikzset{
basic/.style={
draw,
text width=3cm,
drop shadow,
font=\sffamily
},
root/.style={
basic,
rounded corners=2pt,
thin,
align=center,
fill=green!30
},
child node/.style={
basic,
rounded corners=6pt,
thin,
align=center,
fill=green!60,
text width=10em,
anchor=north
},
every child node/.style={child node}
}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
sibling distance=6cm,
edge from parent/.append style={->},
growth parent anchor=south,
>=Latex,
nodes={draw, fill=cyan,
text width=4cm,
text centered}
]
% root of the the initial tree, level 1
\node (root) {Oil Wealth}
% The first level, as children of the initial tree
child {node (A1) {Grandparent}
child {node (B1) {Parent}
child {node (C11) {Child 1}
child {node (D12) {Grandchild}}
}
child {node (C12) {Child 2}
child {node (D11) {Grandchild}}
}
child {node (C13) {Child 3}
child {node (D12) {Grandchild}
child {node (E12) {Grand-Grandchild}}
}}}
};
\draw [->] (C11) -- (D11);
\draw [->] (C12) -- (D11);
\draw [->] (C11) -- (D12);
\draw [->] (C12) -- (D12);
\end{tikzpicture}
\caption{Mine Editing Tex III}
\label{fig: Causal}
\end{figure}
\end{document}
编辑(1):
但是,使用forest
包来绘制树会使代码变得更短更简单:-)
\documentclass[12pt]{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
shadows}
\tikzset{arr/.style = {draw, -{Stealth[length=2mm]}},
every edge/.style = {arr}
}
\usepackage{lipsum} % for dummy text filler
\begin{document}
\section{Tree}\label{sec6}
\lipsum[66]
\begin{figure}[ht]
\centering
\begin{forest}
for tree={
% nodes
draw, semithick, rounded corners,
fill=green!39, drop shadow,
text width=7em, text centered,
font=\sffamily,
% tree
s sep = 4mm,
l sep = 13mm,
edge = {arr},
}
[Oil Wealth, fill=cyan, sharp corners
[Grandparent
[Parent
[Child 1, name=A1
[Grandchild]
]
[Child 2, name=A2
[Grandchild, name=B2]
]
[Child 3
[Grandchild, name=B3
[Grand-Grandchild]
]
]
]
]
]
\draw (A1) edge (B2)
(A1) edge (B3)
(A2) edge (B3);
\end{forest}
\caption{Mine Editing Tex III}
\label{fig: Causal}
\end{figure}
\end{document}
编辑(2): 我再次测试了您的图像代码。为了在页面上看到整个图像,我将其尺寸缩小到原始图像的 0.7。结果如下:
抱歉,但从这张图片几乎不可能看出你想要什么。为了澄清你的问题是什么,你应该提供期望结果的草图,或者至少链接到可能解决你的问题的先前问题和答案(到目前为止你还没有接受其中任何一个。它们都是错的吗?)。这会让猜测更简单......
现在我猜测,受到@Carlatex 回答的启发,您可能会寻找类似这样的内容:
forest
上图使用的 MWE包是:
\documentclass[12pt]{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
shadows}
\tikzset{arr/.style = {draw, -{Stealth[length=2mm]}},
every edge/.style = {arr}
}
\begin{document}
\begin{figure}[ht]
\centering
\begin{forest}
for tree={
% nodes
draw, semithick, rounded corners,
fill=green!39, drop shadow,
text width=7em, text centered,
font=\sffamily,
% tree
s sep = 4mm,
l sep = 13mm,
edge = {arr},
}
[Oil Wealth, fill=cyan, sharp corners
[Grandparent
[Parent
[Child 1, name=A1
[Grandchild 1]
]
[Child 2,
[Grandchild 2, name=B2
[Grand-Grandchild]
]
]
[Child 3, name=A3
[Grandchild 3, name=B3]
]
]
]
]
\draw (A1) edge (B2)
(A3) edge (B2);
\end{forest}
\caption{Mine Editing Tex III}
\label{fig: Causal}
\end{figure}
\end{document}
这就是你要找的吗?
答案2
很难理解你需要什么。
\documentclass{book}
\usepackage{amssymb,amsmath,amsfonts,eurosym,geometry,ulem,graphicx,caption,subcaption, color,setspace,sectsty,comment,footmisc,
%caption, DO NOT LOAD PACKAGES TWICE
natbib,pdflscape,
%subfigure, subfigure is incompatible with subcaption and you already loaded subcaption
array, enumerate, %natbib, DO NOT LOAD PACKAGES TWICE
indentfirst, float, tikz, rotating, lipsum, adjustbox, booktabs, multirow, soul, changepage,threeparttable}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup{colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=black, plainpages=false, pdfpagelabels=true,
urlcolor=blue}
\usepackage[nameinlink, capitalise, noabbrev]{cleveref}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands
\normalem
\onehalfspacing
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}{Proposition}
\newtheorem{conj}{Conjecture}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand{\thesubhyp}{\thehyp\alph{subhyp}}
\newcommand{\red}[1]{{\color{red} #1}}
\newcommand{\blue}[1]{{\color{blue} #1}}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\arraybackslash\hspace{0pt}}m{#1}}
\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}
\usetikzlibrary{shapes,arrows,intersections,arrows.meta,shadows,positioning}
\newcommand{\FixedLengthArrow}{2,0}
\begin{document}
\tikzset{%
block/.style = {rectangle, draw, fill=yellow, text width=5em, text centered, rounded corners, minimum height=2em},
line/.style = {draw, -latex'},
}
\tikzset{
basic/.style={
draw,
text width=3cm,
drop shadow,
font=\sffamily
},
root/.style={
basic,
rounded corners=2pt,
thin,
align=center,
fill=green!30
},
child node/.style={
basic,
rounded corners=6pt,
thin,
align=center,
fill=green!60,
text width=10em,
anchor=north
},
every child node/.style={child node}
}
\begin{figure}[H]
\centering
\begin{tikzpicture}[
sibling distance=6cm,
edge from parent/.append style={->},
growth parent anchor=south,
>=Latex,
nodes={draw, fill=cyan,
text width=4cm,
text centered}
]
% root of the the initial tree, level 1
\node (root) {Oil Wealth}
% The first level, as children of the initial tree
child {
node (A1) {Grandparent}
child {
node (B1) {Parent}
child {
node (C11) {Child}
child {
node (D11) {Grandchild}}}
child {node (C12) {Child}
child {
node (D12) {Grandchild}
child {node (E12) {Grand-Grandchild}}
}
}
child {node (C13) {Child}}
}
}
;
\draw [->] (C11) -- (D11);
\draw [->] (C12) -- (D11);
\draw [->] (C11) -- (D12);
\draw [->] (C12) -- (D12);
\end{tikzpicture}
\caption{Mine Editing Tex III}
\label{fig: Causal}
\end{figure}
\end{document}