对齐 tikz 图像和表格

对齐 tikz 图像和表格

我正在尝试将 tikz 图像的顶部与表格的顶部对齐。到目前为止,我的代码如下:

\documentclass{article}
\usepackage[margin=0.5in, includefoot]{geometry}
\usepackage{tikz}
\usepackage{array}
\usepackage{booktabs}


\newcommand{\graph}[2]{
\begin{tikzpicture}[x=1cm, y=1cm, semitransparent]
\def\width{#2}
\def\hauteur{#1}
\draw[step=1mm, line width=0.1mm, black!30!white] (0,0) grid (\width,\hauteur);
\draw[step=5mm, line width=0.2mm, black!40!white] (0,0) grid (\width,\hauteur);
\draw[step=5cm, line width=0.5mm, black!50!white] (0,0) grid (\width,\hauteur);
\draw[step=1cm, line width=0.3mm, black!90!white] (0,0) grid (\width,\hauteur);
\end{tikzpicture}}

\begin{document}

\begin{table}[t]
\begin{minipage}[t]{0.6\linewidth}
\graph{10}{10}
\end{minipage}
\begin{minipage}[t]{0.35\linewidth}
\begin{tabular}[t]{l l l l l}
\toprule
Angle of & Angle of &  &  & Refractive \\
Incidence i & Refraction r & sin i & sin r & Index n \\
\midrule
& & & & \\
\end{tabular}
\end{minipage}
\end{table}
\end{document}

但是,这会产生以下输出但是,这会产生以下输出,并且我似乎无法使表格与 tikz 图像的顶部对齐。我做错了什么?

答案1

像这样?

\documentclass{article}
\usepackage[margin=0.5in, includefoot]{geometry}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx, adjustbox, caption, floatrow}

\newcommand{\graph}[2]{
\begin{tikzpicture}[x=1cm, y=1cm, semitransparent]
\def\width{#2}
\def\hauteur{#1}
\draw[step=1mm, line width=0.1mm, black!30!white] (0,0) grid (\width,\hauteur);
\draw[step=5mm, line width=0.2mm, black!40!white] (0,0) grid (\width,\hauteur);
\draw[step=5cm, line width=0.5mm, black!50!white] (0,0) grid (\width,\hauteur);
\draw[step=1cm, line width=0.3mm, black!90!white] (0,0) grid (\width,\hauteur);
\end{tikzpicture}}

\begin{document}

\begin{table}[!htb]
\adjustbox{valign = t, raise = -8pt}{\begin{minipage}[t]{0.54\linewidth}\graph{10}{10}
\end{minipage}}
\begin{minipage}[t]{0.35\linewidth}
\begin{tabular}[t]{l l l l l}
\toprule
Angle of & Angle of & & & Refractive \\
Incidence i & Refraction r & sin i & sin r & Index n \\
\midrule
& & & & \\
\end{tabular}\end{minipage}
\end{table}

\end{document} 

在此处输入图片描述

答案2

或使用baseline绘制网格中的选项:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=0.5in, includefoot]{geometry}
\usepackage{tikz}
\usepackage{array, booktabs}


\newcommand{\graph}[2]{
\begin{tikzpicture}[
    baseline=(current bounding box.north),
    x=1cm, y=1cm, semitransparent]
\def\width{#2}
\def\hauteur{#1}
\draw[step=1mm, line width=0.1mm, black!30!white] (0,0) grid (\width,\hauteur);
\draw[step=5mm, line width=0.2mm, black!40!white] (0,0) grid (\width,\hauteur);
\draw[step=5cm, line width=0.5mm, black!50!white] (0,0) grid (\width,\hauteur);
\draw[step=1cm, line width=0.3mm, black!90!white] (0,0) grid (\width,\hauteur);
\end{tikzpicture}}

\begin{document}

\begin{table}[t]
\begin{minipage}[t]{0.55\linewidth}
\graph{10}{10}
\end{minipage}
\begin{minipage}[t]{0.45\linewidth}
\begin{tabular}[t]{l l l l l}
\toprule
Angle of & Angle of &  &  & Refractive \\
Incidence i & Refraction r & sin i & sin r & Index n \\
\midrule
& & & & \\
\end{tabular}
\end{minipage}
\end{table}
\end{document}

答案3

您可以为第一个使用一些附加参数minipage

\begin{minipage}[t][][b]{0.55\linewidth}
  \graph{10}{10}
\end{minipage}%
\begin{minipage}[t]{0.45\linewidth}
  \begin{tabular}[t]{l l l l l}
    \toprule
    Angle of & Angle of &  &  & Refractive \\
    Incidence i & Refraction r & sin i & sin r & Index n \\
    \midrule
    & & & & \\
  \end{tabular}
\end{minipage}

该参数[t]指定了小页面如何向外对齐,以及[b]小页面内部内容的位置。

在此处输入图片描述

相关内容