我使用 TikZ 和定位库绘制了一张家谱,追随贡萨洛。
问题是,在族谱之前生成了一个空白页。有人能解释一下为什么会有空白页,以及如何去掉它吗?我试过摆弄代码来缩小族谱,但没有成功。我在图形周围放了一个边界框,但边界框在同一页上。
为了简洁起见,我省略了连接边。它仍然很长。如果有必要,我可能会进一步精简它,但如果我这样做,这也会增加修复可能无法在实际示例中起作用的风险。
@DavidCarlisle 建议解决方法
\setlength{\textheight}{.8\maxdimen}
这会抑制空白页,但也会抑制任何额外的页面。
\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
\setlength{\oddsidemargin}{-0.6in}
\setlength{\evensidemargin}{-0.10in}
\setlength{\topmargin}{-0.5in}
\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\begin{document}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
\node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
\node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
\node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
\node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
\node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
% % GEN 2 SPOUSES
\node[male,above=of Female2] (Male4) {Male4};
\node[male,above=of Female3] (Male5) {Male5};
\node[male,above=of Male2] (Male2-wife) {Wife};
\node[female,above=of Male3] (Female6) {Female6};
\node[male,below=of Female5] (Male6) {Male6};
% GEN 3
\node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
\node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
\node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
\node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
\node[male,right=of Female3] (Female9) {Female9};
\node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
\node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
\node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
\node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
\node[male,right=of Male6] (Male11) {Male11};
% GEN 3 SPOUSES
\node[male,above=of Female7] (Male12) {Male12};
\node[male,below=of Female7] (Female7-husband) {husband};
\node[male,below=of Female10] (Male13) {Male13};
\node[male,above=of Female11] (Male14) {Male14};
\node[male,below=of Female11] (Male15) {Male15};
\node[female,below=of Male10] (Female12) {Female12};
% GEN 4
\node[female,right=of Male12] (Female7-daughter1) {daughter};
\node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
\node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
\node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
\node[female,below=of Male17] (Female18) {Female18};
\node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
\node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
\node[male,right=of Male15] (Male19) {Male19};
\node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
\node[male,below=of Female20] (Male20) {Male20};
% GEN 5
\node[male,right=of Male20, yshift=1cm] (Male20-son1) {son};
\node[male,below=of Male20-son1] (Male20-son2) {son};
\node[male,below=of Male20-son2] (Male20-son3) {son};
\node[female,below=of Male20-son3] (Male20-daughter1) {daughter};
\end{tikzpicture}
\end{document}
更新:
感谢 Harish 和 Gonzalo 提供的解决方案。它们都有效,很难选择哪一个,但我喜欢 的简单性\usepackage[a4paper,margin=1in]{geometry}
,所以我现在正在使用它。
答案1
您的tikzpicture
文件太大,无法垂直放入页面。LaTeX 会尽力将其放入第一页,然后抛出错误:
Overfull \vbox (147.53874pt too high) has occurred while \output is active
如果不成功,它会将图片推到第二页,而第一页则留空。
该怎么办?使用以下方法将第一页放大一点geometry
:
\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
%\setlength{\oddsidemargin}{-0.6in}
%\setlength{\evensidemargin}{-0.10in}
%\setlength{\topmargin}{-0.5in}
%\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\usepackage[a4paper,margin=1in]{geometry} %%% this line added.
\begin{document}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\noindent
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
\node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
\node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
\node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
\node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
\node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
% % GEN 2 SPOUSES
\node[male,above=of Female2] (Male4) {Male4};
\node[male,above=of Female3] (Male5) {Male5};
\node[male,above=of Male2] (Male2-wife) {Wife};
\node[female,above=of Male3] (Female6) {Female6};
\node[male,below=of Female5] (Male6) {Male6};
% GEN 3
\node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
\node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
\node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
\node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
\node[male,right=of Female3] (Female9) {Female9};
\node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
\node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
\node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
\node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
\node[male,right=of Male6] (Male11) {Male11};
% GEN 3 SPOUSES
\node[male,above=of Female7] (Male12) {Male12};
\node[male,below=of Female7] (Female7-husband) {husband};
\node[male,below=of Female10] (Male13) {Male13};
\node[male,above=of Female11] (Male14) {Male14};
\node[male,below=of Female11] (Male15) {Male15};
\node[female,below=of Male10] (Female12) {Female12};
% GEN 4
\node[female,right=of Male12] (Female7-daughter1) {daughter};
\node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
\node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
\node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
\node[female,below=of Male17] (Female18) {Female18};
\node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
\node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
\node[male,right=of Male15] (Male19) {Male19};
\node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
\node[male,below=of Female20] (Male20) {Male20};
\end{tikzpicture}
\end{document}
这些选项[a4paper,margin=1in]
提供了比默认更大的纸张。因此图片可以放进去。
或者直接使用standalone
类来获取图片。
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\begin{document}
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
\node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
\node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
\node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
\node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
\node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
% % GEN 2 SPOUSES
\node[male,above=of Female2] (Male4) {Male4};
\node[male,above=of Female3] (Male5) {Male5};
\node[male,above=of Male2] (Male2-wife) {Wife};
\node[female,above=of Male3] (Female6) {Female6};
\node[male,below=of Female5] (Male6) {Male6};
% GEN 3
\node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
\node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
\node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
\node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
\node[male,right=of Female3] (Female9) {Female9};
\node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
\node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
\node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
\node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
\node[male,right=of Male6] (Male11) {Male11};
% GEN 3 SPOUSES
\node[male,above=of Female7] (Male12) {Male12};
\node[male,below=of Female7] (Female7-husband) {husband};
\node[male,below=of Female10] (Male13) {Male13};
\node[male,above=of Female11] (Male14) {Male14};
\node[male,below=of Female11] (Male15) {Male15};
\node[female,below=of Male10] (Female12) {Female12};
% GEN 4
\node[female,right=of Male12] (Female7-daughter1) {daughter};
\node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
\node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
\node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
\node[female,below=of Male17] (Female18) {Female18};
\node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
\node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
\node[male,right=of Male15] (Male19) {Male19};
\node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
\node[male,below=of Female20] (Male20) {Male20};
\end{tikzpicture}
\end{document}
答案2
除了垂直问题之外,还有一个问题,\hbox
因为图形太宽,你忘记用 来抑制缩进\noindent
。你也可以通过使用 和 来隐藏图形的宽度、高度和深度,\raisebox
而无需使用额外的包来解决这些问题\makebox
:
\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
\setlength{\oddsidemargin}{-0.6in}
\setlength{\evensidemargin}{-0.10in}
\setlength{\topmargin}{-0.5in}
\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\begin{document}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\noindent\raisebox{-\height}[0pt][0pt]{%
\makebox[\linewidth][l]{%
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
\node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
\node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
\node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
\node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
\node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
% % GEN 2 SPOUSES
\node[male,above=of Female2] (Male4) {Male4};
\node[male,above=of Female3] (Male5) {Male5};
\node[male,above=of Male2] (Male2-wife) {Wife};
\node[female,above=of Male3] (Female6) {Female6};
\node[male,below=of Female5] (Male6) {Male6};
% GEN 3
\node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
\node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
\node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
\node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
\node[male,right=of Female3] (Female9) {Female9};
\node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
\node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
\node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
\node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
\node[male,right=of Male6] (Male11) {Male11};
% GEN 3 SPOUSES
\node[male,above=of Female7] (Male12) {Male12};
\node[male,below=of Female7] (Female7-husband) {husband};
\node[male,below=of Female10] (Male13) {Male13};
\node[male,above=of Female11] (Male14) {Male14};
\node[male,below=of Female11] (Male15) {Male15};
\node[female,below=of Male10] (Female12) {Female12};
% GEN 4
\node[female,right=of Male12] (Female7-daughter1) {daughter};
\node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
\node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
\node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
\node[female,below=of Male17] (Female18) {Female18};
\node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
\node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
\node[male,right=of Male15] (Male19) {Male19};
\node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
\node[male,below=of Female20] (Male20) {Male20};
% GEN 5
\node[male,right=of Male20, yshift=1cm] (Male20-son1) {son};
\node[male,below=of Male20-son1] (Male20-son2) {son};
\node[male,below=of Male20-son2] (Male20-son3) {son};
\node[female,below=of Male20-son3] (Male20-daughter1) {daughter};
\end{tikzpicture}%
}%
}
\clearpage
\end{document}