我试图minipages
在一行中并排插入三个,但是失败了。
以下是我目前能够做的事情:
% -------------------------------------------------------------------
% Packages
\usepackage{tikz}
\usepackage{multirow}
\usetikzlibrary{fit}
\usetikzlibrary{shapes}
% -------------------------------------------------------------------
\begin{document}
\begin{table}
\centering
\makebox[0pt][c]{\parbox{0.7\textwidth}{
\begin{minipage}{0.4\hsize}
\centering
\scalebox{1.1}{
\addtolength{\tabcolsep}{5pt}
\begin{tabular}{c l l}
\cline{2-3}
& \multicolumn{2}{c}{Transactions} \\
\hline
id & Initial & Ordered \\
\hline
1 & c a & a c \\
2 & c b e a & b c e \\
3 & d a c & a c d \\
4 & b a & a b \\
5 & b d c & b c d \\
6 & a b d e & a b d e \\
6 & e a & a e \\
\hline
\end{tabular}}
\end{minipage}
\hfill \vrule \hfill
\begin{minipage}{0.25\hsize}
\centering
\begin{tikzpicture}[level distance = 30pt]
% Tree 1
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {a:2}
child { node {c:1}[sibling distance=30pt]
child { node[rectangle, draw] {1} }
child { node {d:1}
child { node[rectangle, draw] {3} } } } }
child { node {b:1}
child { node {c:1}
child { node {e:1}
child { node[rectangle, draw] {2} } } } }
;
\end{tikzpicture}
\end{minipage}
\hfill \vrule \hfill
\begin{minipage}{0.25\hsize}
\begin{tikzpicture}[level distance = 30pt]
% Tree 2
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {b:1}
child { node {c:1}
child { node {d:1}
child { node[rectangle, draw] {5} } } } }
child { node {a:2}[sibling distance=30pt]
child { node[rectangle, draw] {6} }
child { node {b:1}
child { node[rectangle, draw] {4} } } }
;
\end{tikzpicture}
\end{minipage}}}
\end{table}
\end{document}
我希望将它们并排放置minipages
,并用垂直线分隔,并且,如果可能的话,我想在结果周围添加一个框。
cmhughes,谢谢你的回复。虽然它比我之前用的要好得多,但它占用的空间仍然小于页面的可用空间。我的观点是,为什么fbox
你插入的内容没有占据整个linewidth
页面?
我不确定我愿意提及的是linewidth
,还是textwidth
,甚至是hsize
;我只是想让三个小页面并排放置,使用可用的“整个”页面宽度——当然,要考虑到页面的初始边距。
有没有什么办法可以解决这个问题?
答案1
这是使用简单tabular
(minipage
不需要 s)的另一种可能性;表格宽度将等于\textwidth
:
\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\usepackage{showframe}
\newcolumntype{M}[1]{>{\centering\arraybackslash}p{\dimexpr#1-1.33333\fboxrule\relax}}
\begin{document}
\begin{table}
\setlength\tabcolsep{0pt}
\begin{tabular}{|M{.46\textwidth}|M{.27\textwidth}|M{.27\textwidth}|}
\hline
& & \\
\setlength\tabcolsep{6pt}
\begin{tabular}{c l l}
\cline{2-3}
& \multicolumn{2}{c}{Transactions} \\
\hline
id & Initial & Ordered \\
\hline
1 & c a & a c \\
2 & c b e a & b c e \\
3 & d a c & a c d \\
4 & b a & a b \\
5 & b d c & b c d \\
6 & a b d e & a b d e \\
6 & e a & a e \\
\hline
\end{tabular}
&
\begin{tikzpicture}[level distance = 30pt,baseline=(current bounding box.center)]
% Tree 1
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {a:2}
child { node {c:1}[sibling distance=30pt]
child { node[rectangle, draw] {1} }
child { node {d:1}
child { node[rectangle, draw] {3} } } } }
child { node {b:1}
child { node {c:1}
child { node {e:1}
child { node[rectangle, draw] {2} } } } }
;
\end{tikzpicture}
&
\begin{tikzpicture}[level distance = 30pt,baseline=(current bounding box.center)]
% Tree 2
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {b:1}
child { node {c:1}
child { node {d:1}
child { node[rectangle, draw] {5} } } } }
child { node {a:2}[sibling distance=30pt]
child { node[rectangle, draw] {6} }
child { node {b:1}
child { node[rectangle, draw] {4} } } }
;
\end{tikzpicture}
\\
& & \\
\hline
\end{tabular}
\end{table}
\end{document}
答案2
\documentclass{article}
% -------------------------------------------------------------------
% Packages
\usepackage{tikz}
\usepackage{showframe} %% just to show frames of page
% -------------------------------------------------------------------
\begin{document}
\noindent
\begin{table}
\begin{tabular}{|@{}c@{}|@{}c@{}|@{}c@{}|}\hline
&& \\
\begin{minipage}{0.46\linewidth}
\centering
\addtolength{\tabcolsep}{5pt}
\begin{tabular}{c l l}
\cline{2-3}
& \multicolumn{2}{c}{Transactions} \\
\hline
id & Initial & Ordered \\
\hline
1 & c a & a c \\
2 & c b e a & b c e \\
3 & d a c & a c d \\
4 & b a & a b \\
5 & b d c & b c d \\
6 & a b d e & a b d e \\
6 & e a & a e \\
\hline
\end{tabular}
\end{minipage}%
&%
\begin{minipage}{.27\linewidth}
\centering
\begin{tikzpicture}[level distance = 30pt]
% Tree 1
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {a:2}
child { node {c:1}[sibling distance=30pt]
child { node[rectangle, draw] {1} }
child { node {d:1}
child { node[rectangle, draw] {3} } } } }
child { node {b:1}
child { node {c:1}
child { node {e:1}
child { node[rectangle, draw] {2} } } } }
;
\end{tikzpicture}
\end{minipage}%
&
\begin{minipage}{.27\linewidth}
\centering
\begin{tikzpicture}[level distance = 30pt]
% Tree 2
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {b:1}
child { node {c:1}
child { node {d:1}
child { node[rectangle, draw] {5} } } } }
child { node {a:2}[sibling distance=30pt]
child { node[rectangle, draw] {6} }
child { node {b:1}
child { node[rectangle, draw] {4} } } }
;
\end{tikzpicture}%
\end{minipage}%
\\%
&& \\ \hline
\end{tabular}%
\end{table}
\end{document}
答案3
这是你的代码的一个版本,它可以做你想做的事-我使用了一个简单的fbox
框架来构建结果-你可以使用更奢侈的方式mdframed
如果你希望。
这是我所做的:
- 删除,并纯粹与s
\makebox[0pt][c]{\parbox{0.7\textwidth}{
中的长度一起工作minipage
- 变成
hsize
linewidth
fbox
在整个事情周围添加了一个%
在每个之后添加\end{minipage}
以避免添加额外的空间- 添加
\centering
到每个minipage
梅威瑟:
\documentclass{article}
% -------------------------------------------------------------------
% Packages
\usepackage{tikz}
% -------------------------------------------------------------------
\begin{document}
\begin{table}
\centering
\fbox{%
\begin{minipage}{0.4\linewidth}
\centering
\addtolength{\tabcolsep}{5pt}
\begin{tabular}{c l l}
\cline{2-3}
& \multicolumn{2}{c}{Transactions} \\
\hline
id & Initial & Ordered \\
\hline
1 & c a & a c \\
2 & c b e a & b c e \\
3 & d a c & a c d \\
4 & b a & a b \\
5 & b d c & b c d \\
6 & a b d e & a b d e \\
6 & e a & a e \\
\hline
\end{tabular}
\end{minipage}%
\hfill \vrule \hfill
\begin{minipage}{0.25\linewidth}
\centering
\begin{tikzpicture}[level distance = 30pt]
% Tree 1
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {a:2}
child { node {c:1}[sibling distance=30pt]
child { node[rectangle, draw] {1} }
child { node {d:1}
child { node[rectangle, draw] {3} } } } }
child { node {b:1}
child { node {c:1}
child { node {e:1}
child { node[rectangle, draw] {2} } } } }
;
\end{tikzpicture}
\end{minipage}%
\hfill \vrule \hfill
\begin{minipage}{0.25\linewidth}
\centering
\begin{tikzpicture}[level distance = 30pt]
% Tree 2
\tikzstyle{every node}=[circle, draw, minimum size=5pt,
scale=0.8]
\node {\#:3}
child { node {b:1}
child { node {c:1}
child { node {d:1}
child { node[rectangle, draw] {5} } } } }
child { node {a:2}[sibling distance=30pt]
child { node[rectangle, draw] {6} }
child { node {b:1}
child { node[rectangle, draw] {4} } } }
;
\end{tikzpicture}
\end{minipage}%
}
\end{table}
\end{document}