我尝试使用 旋转迷你页面环境中的 tikz 树和表格,\landscape
因为表格旁边的树太宽了。现在,树和表格没有居中。表格的最后一列几乎不在页面上。因此,我尝试使用 geometry 包并将\newgeometry{left=5mm,right=5mm,top=5mm,bottom=5mm}
边距设置为 5mm(我只想将它用于单页)。不幸的是,这不起作用。我总是收到错误。此外,表格中第一列的文本不像其他列那样居中。我做错了什么?这是我的代码:
\documentclass[doc,apacite]{apa}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%%%%Tikz%%%%%%
\usepackage{tikz}
\usetikzlibrary{trees,matrix,fit}
\usetikzlibrary{shapes}
%%%%Table%%%%%
\usepackage{ctable} % needed for \cmidrule{}
\usepackage{multirow} % needed for \multirow{}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
%%%%%%%%%%%%%%
\usepackage{pgfkeys}
\usepackage{lscape}
\usepackage{geometry}
\geometry{paper=a4paper, left=35mm, right=35mm, top=35mm, bottom=30mm}
\newlength\sibdist
\setlength\sibdist{1cm}
%\newcommand\sibdist{1.5cm}
\begin{document}
\newgeometry{left=5mm,right=5mm,top=5mm,bottom=5mm}
\footnotesize
\begin{landscape}
\begin{minipage}[t]{290pt}
\vspace{40pt}
%\hspace{0pt}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.0cm, sibling distance=6cm]
\tikzstyle{level 2}=[level distance=5.0cm, sibling distance=4cm]
\tikzstyle{level 3}=[level distance=5.0cm, sibling distance=4cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
\begin{tikzpicture}[grow=right,
sloped,
myrect/.style={draw=black,fill=white!100,text width=3cm,align=center,inner sep=5pt},
myellipse/.style={ellipse,draw=black,fill=black!0,inner sep=2pt,text width=2.8cm,align=center},
myrect2/.style={rectangle,rounded corners = 15,draw=black,fill=white!100,text width=3.3cm,align=center,inner sep=5pt},]
\node[myrect]{ario}
child {
node[myrect2]{itari}
child {
node[label=right:
,myrect2]{ntolog} {}
child {node[myrect2]
{ards}
edge from parent
node[above] {$R$}
node[below] {}}
child {node[myrect2]
{ndcy tow}
edge from parent
node[above] {$R+k$}
node[below] {}}
edge from parent
node[above] {$D-k$}
node[below] {}
}
child {
node[myrect2]
{omin}
edge from parent
node[above] {$D+k$}
node[below] {}
}
edge from parent
node[above] {}
node[below] {$u$}
}
child {
node[myrect2]{nse}
edge from parent
node[above] {$u-k$}
node[below] {}
};
\end{tikzpicture}
\end{minipage}
\hfill
\begin{minipage}[t]{150pt}
\vspace{0pt}
\hspace{10pt}
%\begin{table}[h]
%\renewcommand{\arraystretch}{2.5}
\begin{tabular}{|m{1.6cm}|m{1.6cm}|m{1.6cm}|m{1.6cm}|}
nt & nt & nt & nt \\ \hline \hline
\rule{0pt}{60pt} e & le & ble & able \\ \hline
\rule{0pt}{60pt} H & H & H & H \\ \hline
\rule{0pt}{60pt} m & m & m & e \\ \hline
\rule{0pt}{60pt} le & le & le & le
\end{tabular}
%\renewcommand{\arraystretch}{1}
%\end{table}
\end{minipage}
\end{landscape}
\restoregeometry
\end{document}
答案1
你的minipage
宽度不合适。我把它改成了0.5\textwidth
。你给出的尺寸太大了,rounded corners
我把它改成了。另外,你的隐形规则没有深度,导致第一列对齐不正确。我已在(适当更改)3mm
中添加了深度。最后,你加载了许多不必要的包,例如。(由提供)\rule[-27pt]{0pt}{60pt}
-27pt
ctable
\cmidrule
booktabs
代码:
\documentclass[doc,apacite]{apa}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%%%%Tikz%%%%%%
\usepackage{tikz}
\usetikzlibrary{trees,matrix,fit}
\usetikzlibrary{shapes}
%%%%Table%%%%%
%\usepackage{ctable} % needed for \cmidrule{}
\usepackage{multirow} % needed for \multirow{}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
%%%%%%%%%%%%%%
\usepackage{pgfkeys}
\usepackage{lscape}
\usepackage{geometry}
\geometry{paper=a4paper, left=35mm, right=35mm, top=35mm, bottom=30mm}
\newlength\sibdist
\setlength\sibdist{1cm}
%\newcommand\sibdist{1.5cm}
\begin{document}
\newgeometry{left=5mm,right=5mm,top=5mm,bottom=5mm}
\footnotesize
\begin{landscape}
\begin{minipage}{0.5\textwidth} %% changed this
\vspace{40pt}
%\hspace{0pt}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.0cm, sibling distance=6cm]
\tikzstyle{level 2}=[level distance=5.0cm, sibling distance=4cm]
\tikzstyle{level 3}=[level distance=5.0cm, sibling distance=4cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
\begin{tikzpicture}[grow=right,
sloped,
myrect/.style={draw=black,fill=white!100,text width=3cm,align=center,inner sep=5pt},
myellipse/.style={ellipse,draw=black,fill=black!0,inner sep=2pt,text width=2.8cm,align=center},
myrect2/.style={rectangle,rounded corners =3mm,draw=black,fill=white!100,text width=3.3cm,align=center,inner sep=5pt},]
\node[myrect]{ario}
child {
node[myrect2]{itari}
child {
node[label=right:
,myrect2]{ntolog} {}
child {node[myrect2]
{ards}
edge from parent
node[above] {$R$}
node[below] {}}
child {node[myrect2]
{ndcy tow}
edge from parent
node[above] {$R+k$}
node[below] {}}
edge from parent
node[above] {$D-k$}
node[below] {}
}
child {
node[myrect2]
{omin}
edge from parent
node[above] {$D+k$}
node[below] {}
}
edge from parent
node[above] {}
node[below] {$u$}
}
child {
node[myrect2]{nse}
edge from parent
node[above] {$u-k$}
node[below] {}
};
\end{tikzpicture}
\end{minipage}% % added a % at the end of line
\hfill
\begin{minipage}{0.5\textwidth}
\vspace{0pt}
\hspace{10pt}
%\begin{table}[h]
%\renewcommand{\arraystretch}{2.5}
\begin{tabular}{|m{1.6cm}|m{1.6cm}|m{1.6cm}|m{1.6cm}|}
nt & nt & nt & nt \\ \hline \hline
\rule[-27pt]{0pt}{60pt} e & le & ble & able \\ \hline
\rule[-27pt]{0pt}{60pt} H & H & H & H \\ \hline
\rule[-27pt]{0pt}{60pt} m & m & m & e \\ \hline
\rule[-27pt]{0pt}{60pt} le & le & le & le \\ \hline %% added
\end{tabular}
%\renewcommand{\arraystretch}{1}
%\end{table}
\end{minipage}
\end{landscape}
\restoregeometry
\end{document}
答案2
您不需要geometry
,\newgeometry
特别是对于像这样的提交类apa
。
这是一种不需要猜测类的分页参数的方法。 周围tabular
的tikzpicture
只是为了垂直居中。\newsavebox
只是为了避免
\makebox[0pt]{\smash{%
<all the material for picture and table>
}}
这会使代码更难维护。
\documentclass[doc,apacite]{apa}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%%%%Tikz%%%%%%
\usepackage{tikz}
\usetikzlibrary{trees,matrix,fit}
\usetikzlibrary{shapes}
%%%%Table%%%%%
\usepackage{ctable} % needed for \cmidrule{}
\usepackage{multirow} % needed for \multirow{}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
%%%%%%%%%%%%%%
\usepackage{pgfkeys}
\usepackage{lscape}
\newlength\sibdist
\setlength\sibdist{1cm}
\newsavebox\sibsavebox
\begin{document}
\begin{landscape}
\footnotesize
\begin{lrbox}{\sibsavebox}
\begin{tabular}{@{}c@{}}
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.0cm, sibling distance=6cm]
\tikzstyle{level 2}=[level distance=5.0cm, sibling distance=4cm]
\tikzstyle{level 3}=[level distance=5.0cm, sibling distance=4cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
\begin{tikzpicture}[
grow=right,
sloped,
myrect/.style={
draw=black,fill=white!100,text width=3cm,align=center,inner sep=5pt
},
myellipse/.style={
ellipse,draw=black,fill=black!0,inner sep=2pt,text width=2.8cm,align=center
},
myrect2/.style={
rectangle,rounded corners = 15,draw=black,fill=white!100,text width=3.3cm,
align=center,inner sep=5pt
},
]
\node[myrect]{ario}
child {
node[myrect2]{itari}
child {
node[label=right:
,myrect2]{ntolog} {}
child {node[myrect2]
{ards}
edge from parent
node[above] {$R$}
node[below] {}}
child {node[myrect2]
{ndcy tow}
edge from parent
node[above] {$R+k$}
node[below] {}}
edge from parent
node[above] {$D-k$}
node[below] {}
}
child {
node[myrect2]
{omin}
edge from parent
node[above] {$D+k$}
node[below] {}
}
edge from parent
node[above] {}
node[below] {$u$}
}
child {
node[myrect2]{nse}
edge from parent
node[above] {$u-k$}
node[below] {}
};
\end{tikzpicture}
\end{tabular}%
\hspace{1cm}% <------------------------------------------ adjust here
\begin{tabular}{|m{1.6cm}|m{1.6cm}|m{1.6cm}|m{1.6cm}|}
nt & nt & nt & nt \\ \hline \hline
\rule{0pt}{60pt} e & le & ble & able \\ \hline
\rule{0pt}{60pt} H & H & H & H \\ \hline
\rule{0pt}{60pt} m & m & m & e \\ \hline
\rule{0pt}{60pt} le & le & le & le
\end{tabular}
\end{lrbox}
\centering
\vspace*{\fill}
\makebox[0pt]{\smash{\usebox{\sibsavebox}}}
\vspace*{\fill}
\end{landscape}
\end{document}