Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to insert three minipages, side by side, in a line, but I'm failing miserably.

Here's what I've been able to do so far:

% -------------------------------------------------------------------
% 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}

screenshot

I'd like to have the minipages side by side, separated by vertical lines, and, if possible, I'd like to add a box around the result.

cmhughes, thanks for your reply. Although it works much better than what I had, it still uses less than the available space in the page. My point is, why isn't the fbox you've inserted taking the entire linewidth of the page.

I'm not sure if it is the linewidth, or the textwidth, or even the hsize I'm willing to refer to; I just would like to have the three minipages, side-by-side, using the "whole" page width available -- naturally, considering the initial margins of the page.

Is there any solution for this?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Here's another possibility using a simple tabular (no minipages required); the tabular width will be equal to \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}

enter image description here

share|improve this answer
    
That's exactly what I've been looking for; would you mind just to point out what was that you've done, concerning the \newcolumntype{M}[1]{>{\centering\arraybackslash}p{\dimexpr#1-1.33333\fboxrule\‌​relax}} definition/usage. Thanks very much! –  Rubens Jan 13 '13 at 3:54
1  
@Rubens since the tabular has three columns and four vertical lines that have some width, each column width has to be reduced by 4/3 of the line width; \dimexpr is an e-TeX command allowing to perform calculations with dimensions. –  Gonzalo Medina Jan 13 '13 at 3:57
    
Thanks for your reply, Gonzalo! So, dimexpr#1-1.33333\fboxrule takes, for example, {.46\textwidth}, subtracts 1.3 * \fboxrule from it, and set p{resulting_size\relax}? If so, \newcolumntype{M}[1]{>{\centering\arraybackslash}p{...}} creates a new type of column that is inserting the contents into a p{}, and \centering the p{} block. Is it right? The > and \arraybackslash are just part of the syntax, or do they have a special meaning? –  Rubens Jan 13 '13 at 11:39
1  
@Rubens: The first part (the one about the width calculation) is almost perfect; \relax is only used so TeX stops scanning for further dimensions. The second part (the one about the new column type) is correct. The >{code} construct inserts code before the column content is typeset; in this case, \centering is inserted before the column content is typeset, so the contents get centered. \centering redefines the line changing command ` \\ ` and \arraybackslash reverts to the original definition. More details can be found in the documentation of the array package. –  Gonzalo Medina Jan 13 '13 at 14:33

Here's a version of your code that does what you want- I've used a simple fbox to frame the result- you could get more extravagant using mdframed if you wish.

screenshot

Here's what I did:

  • removed \makebox[0pt][c]{\parbox{0.7\textwidth}{, and worked purely with the lengths in the minipages
  • changed hsize to linewidth
  • added an fbox around the whole thing
  • added % after each \end{minipage} to avoid the extra space being added
  • added \centering to each minipage

MWE:

\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}
share|improve this answer
    
Thanks for the reply; there's quite some space left by the right side; is there anyway to force the picture to take place over the page line in a whole? I mean, is there a way to increase the width, and center the entries in each field? –  Rubens Jan 13 '13 at 2:26
    
@Rubens oops, forgot the centering in the third minipage, have corrected :) –  cmhughes Jan 13 '13 at 2:28
    
@cmhughes regarding the first new requirement (in the OP's comment) you can enclose the whole thing in another minipage of the appropriate width: \fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule}\begin{minipage}‌​{-45\linewidth}...\end{minipage}\end{minipage}}. –  Gonzalo Medina Jan 13 '13 at 2:43
    
Would you mind to see my edit? I'm still not satisfied with the width of the resulting picture. –  Rubens Jan 13 '13 at 2:44
    
@Rubens: see my previous comment. –  Gonzalo Medina Jan 13 '13 at 2:49
 \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}

enter image description here

share|improve this answer
    
It's even prettier now, with the inner contents not plastered with the vertical lines; the showframe is very handy, didn't know there was such thing. Would you mind to explain what is that with the \renewcommand{\arraystretch}{1.3} and the subsequent \renewcommand of the same \arraystrech? Also, what are all those @ in the tabular definition? A last question: how could I add a small padding between the top and bottom lines and the content of each minipage? Thank you all for the support. –  Rubens Jan 13 '13 at 3:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.