我正在尝试使用包绘制树形图forest
。为了使图表适合页边距,我将子树向下移动NastranBulkData 对象,如您在图片中看到的。然而,NastranCaseControl 对象和NastranBulkData 对象导致图表无法适应页边距。
我怎样才能删除这些空白,以便NastranBulkData 对象和NastranSubcaseResult 对象向左移动?理想情况下,它们应该以这样的方式移动,即与其他 Nastran 案例控制条目相关的对象以及从NastranBulkData 对象等于树中子项之间的分离(但我不太在意这个)。
梅威瑟:
% Class
\documentclass[10pt]{article}
% Set paper geometry
\usepackage[letterpaper,margin=1in]{geometry}
% Forest package
\usepackage[edges]{forest}
% Document
\begin{document}
\begin{figure}[hbt!]
\centering
\begin{forest}
for tree={ % style of tree nodes
draw, semithick, rounded corners,
align = center,
inner sep = 2mm,
anchor=north,
% styles of tree
forked edge,
l sep = 6mm,
fork sep = 3mm,
}
[\texttt{NastranAnalysis}\\object
[\texttt{NastranExecutiveControl}\\object
[Solution\\sequence \#]
]
[\texttt{NastranCaseControl}\\object
[\texttt{NastranSubcase}\\object array]
[Objects related to\\other \textsc{Nastran}\\case control entries]
]
[\texttt{NastranBulkData}\\object
[\texttt{Grid}\\object array, fork sep=3cm, l*=5, name=grid]
[Objects related to other \\\textsc{Nastran} bulk data cards, fork sep=3cm, l*=5]
[\texttt{NastranPart}\\object array, fork sep=3cm, l*=5
[\texttt{NastranPart}\\object 1]
[\texttt{NastranPart}\\object 2]
[\dots]
]
]
[\texttt{NastranSubcaseResult}\\object array]
]
\end{forest}
\end{figure}
\end{document}
答案1
请尝试以下操作:
\documentclass[10pt]{article}
% Set paper geometry
\usepackage[letterpaper,margin=1in]{geometry}
% Forest package
\usepackage[edges]{forest}
% Document
\begin{document}
\begin{figure}[hbt!]
\centering
\begin{forest}
for tree={ % style of tree nodes
draw, semithick, rounded corners,
font=\small, % <---
align = center,
inner sep = 2mm,
anchor=north,
% styles of tree
forked edge,
s sep = 2mm,
l sep = 6mm,
fork sep = 3mm,
}
[\texttt{NastranAnalysis}\\object
[\texttt{NastranExecutiveControl}\\object
[Solution\\sequence \#]
]
[\texttt{NastranCaseControl}\\object
[\texttt{NastranSubcase}\\object array]
[Objects related to\\other \textsc{Nastran}\\case control entries]
]
[\texttt{NastranBulkData}\\object
[, l*=4,coordinate
[\texttt{Grid}\\object array]
[Objects related to other \\\textsc{Nastran} bulk data cards]
[\texttt{NastranPart}\\object array,
[\texttt{NastranPart}\\object 1]
[\texttt{NastranPart}\\object 2]
[\dots]
]
]
]
[\texttt{NastranSubcaseResult}\\object array]
]
\end{forest}
\end{figure}
\end{document}
在代码中添加了节点为的附加级别coordinate
。字体大小也减小为\small
。一个选项是减小inner sep
到 1mm 并使用正常字体大小。
(红线表示文本区域边框)
答案2
在森林中移动节点的可靠方法是使用密钥before computing xy
。(我还添加了calign child=2
以避免扭结。)
\documentclass[10pt]{article}
% Set paper geometry
\usepackage[letterpaper,margin=1in,showframe]{geometry}
% Forest package
\usepackage[edges]{forest}
% Document
\begin{document}
\begin{figure}[hbt!]
\centering
\begin{forest}
for tree={ % style of tree nodes
draw, semithick, rounded corners,
align = center,
inner sep = 2mm,
anchor=north,
% styles of tree
forked edge,
l sep = 6mm,
fork sep = 3mm,s sep=0.35em
}
[\texttt{NastranAnalysis}\\object
[\texttt{NastranExecutiveControl}\\object
[Solution\\sequence \#]
]
[\texttt{NastranCaseControl}\\object
[\texttt{NastranSubcase}\\object array]
[Objects related to\\other \textsc{Nastran}\\case control entries]
]
[\texttt{NastranBulkData}\\object,before computing
xy={s+=-9em},calign child=2
[\texttt{Grid}\\object array, fork sep=3cm, l*=5, name=grid]
[Objects related to other \\\textsc{Nastran} bulk data cards, fork sep=3cm, l*=5]
[\texttt{NastranPart}\\object array, fork sep=3cm, l*=5
[\texttt{NastranPart}\\object 1]
[\texttt{NastranPart}\\object 2]
[\dots]
]
]
[\texttt{NastranSubcaseResult}\\object array,
before computing xy={s+=-9em}]
]
\end{forest}
\end{figure}
\end{document}
该showframe
选项用于显示生成的树确实适合页面,当然您希望将其放置在文档中。