垂直对齐表格和 TiKz 图片

垂直对齐表格和 TiKz 图片

我有以下代码。我想将表格拉到页面顶部,以便表格和 tikz 图片在页面顶部垂直对齐(如图所示)。我需要你在这方面的帮助。

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

在此处输入图片描述

答案1

任何元素tikzpicture都被视为简单元素char,并根据其baseline默认south锚点进行对齐(参见 pgfmanual 第 124 页。因此,在您的代码中,两个表格的中心点都与 tikzpicture 的南点对齐。

您可以使用 tikzpicture 的选项更改此对齐方式baseline。您可以决定在何处将图片与baseline=(current bounding box.north)baseline=(current bounding box.center)或类似表达式对齐。

tabular还可以使用可选参数沿顶部、中心或底部对齐它们:\begin{tabular}[t]{...}

一个居中对齐的示例:

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

在此处输入图片描述

答案2

实现此目的的一个简单方法是将表作为其中的一部分tikzpicture,即将其放入节点中。

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

在此处输入图片描述

答案3

我使用 强力整理它minipages。这是一种简单的使用方法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}

相关内容