3

I have the following codes. I want to pull the tables to the top of the page so that tables and the tikz picture are aligned vertically at top of the page (as shown in the figure). I need your help in this direction.

\documentclass[12pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}
\begin{tikzpicture}[scale=0.4]
\draw[fill=white] (-45,-5) rectangle (45,65);
\end{tikzpicture}
\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}

\end{document}

enter image description here

1

Any tikzpicture is considered as a simple char and it's aligned according it's baseline which by default is its south anchor (see page 124 in pgfmanual. Therefore, in your code the central point of both tabulars are aligned with tikzpicture's southern point.

You can change this alignment with tikzpicture's option baseline. You can decide where to align the picture with baseline=(current bounding box.north) or baseline=(current bounding box.center) or similar expressions.

About tabular you can also use the optional parameter to align them along it's top, center or bottom: \begin{tabular}[t]{...}.

One example aligning to center:

\documentclass[12pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}
\begin{tikzpicture}[baseline=(current bounding box.center), scale=0.4]
\draw[fill=white] (-45,-5) rectangle (45,65);
\end{tikzpicture}
\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}
\end{document}

enter image description here

  • [t] for the tabulars and [baseline=(current bounding box.north),scale=0.4] for the tikzpicture worked exactly as I wanted. – bkarpuz Dec 24 '18 at 12:37
  • How can I add a new table below of the figure (by preserving the previous two)? – bkarpuz Jan 11 at 13:58
  • 1
    @bkarpuz You can declare tabular inside tabular, so declare new tabular that contains pervious elements and the new tabular can be declared as the central element on the second row. – Ignasi Jan 11 at 17:18
5

A simple way to achieve this is to make the tables part of the tikzpicture, i.e. to put them in nodes.

\documentclass[12pt]{standalone}

\usepackage{tikz}

\begin{document}


\begin{tikzpicture}[scale=0.4]
\draw[fill=white] (-45,-5) rectangle (45,65);
\node[anchor=north east] at (-45,65){\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}};
\node[anchor=north west] at (45,65) {\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}
};
\end{tikzpicture}
\end{document}

enter image description here

1

I arrange it by brute force using minipages. It's a easy way to work with floats.

\documentclass[12pt]{standalone}
\usepackage{tikz}
\begin{document}
\noindent \begin{minipage}{1.1cm}\vspace*{-7cm}{
\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
  \hline
\end{tabular}
}
\end{minipage}

\begin{minipage}{35.9cm}
\begin{tikzpicture}[scale=0.4]
  \draw[fill=white] (-45,-5) rectangle (45,65);
\end{tikzpicture}
\end{minipage}

\begin{minipage}{1.2cm}\vspace*{-7cm}{
\begin{tabular}{|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\ \hline
  1 & A \\
\hline
\end{tabular}
}
\end{minipage}
\end{document}
  • 1
    You do not use any float and minipage has, in fact, nothing to do with floats… – TeXnician Dec 21 '18 at 9:04
  • Well, the idea was to refer the minipage as 'floating' element. Sorry, if i didn't use the figure or table enviroment who does create a floating element. – kraDracsO Dec 22 '18 at 22:17
  • I just mentioned it because in terms of TeX floating is a very different concept than, say, in web design… – TeXnician Dec 23 '18 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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