0

I'm trying to align the top of a tikz image with the top of a table. My code so far is the following:

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

However, this produces the following output However, this produces the following output and I can't seem to get the table to align with the top of the tikz image. What am I doing wrong?

1
  • To overlap boxes you need to write one, back up, then write the other in the same place. Usually we use \rlap, \llap, \smash and/or \raisebox to do this, although \hspace with negative values also works. Aug 2, 2017 at 13:24

3 Answers 3

2

Like this?

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

enter image description here

1

or use baseline option in drawing grid:

enter image description here

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

You can use some additional parameters for the first 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}

The parameter [t] specifies how the minipage is aligned to the outside and the [b] the position of the contents inside the minipage.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .