4

I am trying to get two tabular constructs side-by-side with a tikz figure in between and can't seem to get what I want using the minipage construct. Here is the code I have

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{picture}
\usepackage{caption}
\usepackage{tikz-rdf}
\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{tkz-berge}

\usetikzlibrary{shapes,shapes.callouts,,decorations.text,shapes.misc,decorations.pathmorphing,shapes.geometric,backgrounds,fit,positioning,arrows}

\begin{document}

\begin{figure}[t]
\begin{minipage}[b]{.30\textwidth}
  \centering
  \scalebox{.6}{
      \begin{tabular}{| p{1.5cm} | c | c | c |} \hline
        title & nationality & locatedIn & salary \\ 
        ?t & ?n & ?p & ?s \\ \hline
        Professor  &  American & USA &  \$100,000 \\ \hline
        Professor  &  American & China &  \$100,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ \hline
      \end{tabular}
  }
\end{minipage}
%
\begin{minipage}{.2\textwidth}
              \begin{tikzpicture}
                \draw[
                     -triangle 90,
                        line width=1mm,
                        postaction={draw, line width=0.3cm, shorten >=0.3cm, -}
                ] (0,0) -- (1,0);
           \end{tikzpicture}


\end{minipage}
        %
 \begin{minipage}[b]{.30\textwidth}%{80mm}
        \centering
                 \scalebox{.6}{
              \begin{tabular}{| p{1.5cm} | c | c | c |} \hline
                title & nationality & locatedIn & salary \\ 
                ?t & ?n & ?p & ?s \\ \hline
                Professor  &  American & USA &  \$100,000 \\ \hline
                Professor  &  American & China &  \$100,000 \\ \hline
                Assistant Professor  &  Canadian & China &  \$135,000 \\ \hline
              \end{tabular}
            }
        \end{minipage}
        \end{figure}
          \captionof{table}{Current and Mean B with a Reversed Polarity}

        \end{document}

The output I am getting is the following. Any help would be appreciated.

enter image description here

lockstep
  • 250,273
ozsu
  • 2,385

4 Answers4

4

You are using twocolumn so \linewidth is rather less than half \textwidth but your table widths add up to more than that, don't you want to base the widths on \linewidth? or \columnwidth, probably better.

David Carlisle
  • 757,742
  • Yes, I do. Thanks. One more question -- how do I get the bottom of the two tables aligned? I thought putting [b] after minipage should do that, but it doesn't seem to be accomplishing what I wanted. – ozsu Mar 05 '12 at 08:39
  • you need a [b] on the \begin{tabular} so the table aligns on its bottom row (also don't forget to upvote&accept if it works:-) – David Carlisle Mar 05 '12 at 09:17
  • Thank you. FOr some reason, it also pushes the arrow down (i.e., it aligns the tikz figure at the bottom as well). – ozsu Mar 05 '12 at 09:29
  • well yes if latex aligns three things in a row it does so so their baselines line up, by default the baselines of the table are in the center. If you [b] align the tables you will need to raise the arrow, I don't know tikz at all it may have an alignment option or you could put the tikzpicture into a \raisebox{5\baselineskip}{....} or some other length and raise it by whatever you need – David Carlisle Mar 05 '12 at 09:56
3

It you wrap them all in one minipage they get placed next to each other. Also you should be using figure* in a twocolumn document:

\begin{figure*}[t]
  \begin{minipage}{\textwidth}
      ...
  \end{minipage}
\end{figure*}

I added \usepackage{showframe} so that you can see where the margins are and adjust your settings as desired:

enter image description here

Code:

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{picture}
\usepackage{caption}
%\usepackage{tikz-rdf}
\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{tkz-berge}

\usepackage{showframe}

\usetikzlibrary{shapes,shapes.callouts,,decorations.text,shapes.misc,decorations.pathmorphing,shapes.geometric,backgrounds,fit,positioning,arrows}

\begin{document}

\begin{figure}[t] \begin{minipage}{\textwidth} \begin{minipage}[b]{.30\textwidth} \centering \scalebox{.6}{ \begin{tabular}{| p{1.5cm} | c | c | c |} \hline title & nationality & locatedIn & salary \ ?t & ?n & ?p & ?s \ \hline Professor & American & USA & $100,000 \ \hline Professor & American & China & $100,000 \ \hline Assistant Professor & Canadian & China & $45,000 \ \hline Assistant Professor & Canadian & China & $45,000 \ \hline Assistant Professor & Canadian & China & $45,000 \ \hline \end{tabular} } \end{minipage} % \begin{minipage}{.2\textwidth} \begin{tikzpicture} \draw[ -triangle 90, line width=1mm, postaction={draw, line width=0.3cm, shorten >=0.3cm, -} ] (0,0) -- (1,0); \end{tikzpicture} \end{minipage} % \begin{minipage}[b]{.30\textwidth}%{80mm} \centering \scalebox{.6}{ \begin{tabular}{| p{1.5cm} | c | c | c |} \hline title & nationality & locatedIn & salary \ ?t & ?n & ?p & ?s \ \hline Professor & American & USA & $100,000 \ \hline Professor & American & China & $100,000 \ \hline Assistant Professor & Canadian & China & $135,000 \ \hline \end{tabular} } \end{minipage} \captionof{table}{Current and Mean B with a Reversed Polarity} \end{minipage} \end{figure} \end{document}

Peter Grill
  • 223,288
3

Simply add a % after your \end{minipage} commands:

...
\end{minipage}%
%
\begin{minipage}{.2\textwidth}
...

enter image description here

Daniel
  • 37,517
  • @user8801: You are welcome. One point: Here at stackexchange we thank [user] by upvoting [his/her] answer (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote). Additionally, please finally accept the answer that helped you most (by clicking on the checkmark). – Daniel Mar 05 '12 at 10:30
1

Matrices!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,positioning}
\begin{document}
\begin{table}
\centering%
\begin{tikzpicture}[scale=0.6,column 1/.style={nodes={text width=1.5cm}}]
\matrix[matrix of nodes,
            draw,
            %outer sep=2mm,
            %
            ] (firsttable) {
        title & nationality & locatedIn & salary \\ 
        ?t & ?n & ?p & ?s \\ \hline
        Professor  &  American & USA &  \$100,000 \\ \hline
        Professor  &  American & China &  \$100,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ \hline
        Assistant Professor  &  Canadian & China &  \$45,000 \\ 
};

\matrix[matrix of nodes,
            draw,
            right = 2 cm of firsttable.south east,
                        anchor= south west,
            ] (secondtable) {
                title & nationality & locatedIn & salary \\ 
                ?t & ?n & ?p & ?s \\ \hline
                Professor  &  American & USA &  \$100,000 \\ \hline
                Professor  &  American & China &  \$100,000 \\ \hline
                Assistant Professor  &  Canadian & China &  \$135,000 \\
};
 \draw[
                     -triangle 90,
                        line width=1mm,
                        postaction={draw, line width=0.3cm, shorten >=0.3cm, -}
                ] ([xshift=3mm]firsttable.east |- secondtable.west) -- ([xshift=-3mm]secondtable.west);

\foreach \x in {1,2,3}{
\draw (firsttable.north west -| firsttable-1-\x.north east) |- (firsttable.south west -| firsttable-4-\x.north east);
}
\foreach \x in {1,2,3}{
\draw (secondtable.north west -| secondtable-1-\x.north east) |- (secondtable.south west -| secondtable-4-\x.north east);
}
\end{tikzpicture}
\caption{Current and Mean B with a Reversed Polarity}
\label{tikztable}
\end{table}
\end{document}

enter image description here

EDIT: I've repositioned the table and drawn verticle seperators. However it is strongly recommended to avoid vertical seperators but that's a whole another story and I am not literate enough to comment on that.

percusse
  • 157,807
  • This is a very interesting solution, never thought of that. Could you please also tell me how to align the tables at the bottom with this solution? Also, I assume you cannot get vertical separators for the columns? – ozsu Mar 05 '12 at 09:35