Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with vertical alignment in a tabular environment with tikzpicture.

My code so far is:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tabular}{ccccc}
\begin{tikzpicture}
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,1.6);
\end{tikzpicture} 
& = & 
\begin{tikzpicture}
  \draw[step=0.2cm,gray,very thin] (0,0) grid (3,1.6);
\end{tikzpicture}
& * & 
\begin{tikzpicture}
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,3);
\end{tikzpicture}
\end{tabular}
\end{document}

which gives a result: enter image description here

But what I want is more like this: enter image description here

How can I do it?

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

You can use the baseline option to your tikzpictures. (Use $\ast$ instead of plain *, to adjust the baseline)

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz}
\begin{document}
\begin{tabular}{ccccc}
    \begin{tikzpicture}[baseline={(0,1.4-1.4/2)}]
        \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,1.6);
    \end{tikzpicture} 
    & = & 
    \begin{tikzpicture}[baseline={(0,1.4-1.4/2)}]
        \draw[step=0.2cm,gray,very thin] (0,0) grid (3,1.6);
    \end{tikzpicture}
    & $\ast$ & 
    \begin{tikzpicture}[baseline={(0,2.8-1.4/2)}]
        \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,3);
    \end{tikzpicture}
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
Thank you very much! –  anfneub Mar 23 at 13:23
add comment

One way is to set the baseline key of the environment

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tabular}{ccccc}
\begin{tikzpicture}[baseline=(current bounding box.center)]
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,1.6);
\end{tikzpicture} 
& = & 
\begin{tikzpicture}[baseline=(current bounding box.center)]
  \draw[step=0.2cm,gray,very thin] (0,0) grid (3,1.6);
\end{tikzpicture}
& * & 
\begin{tikzpicture}[baseline={([yshift=0.7cm]current bounding box.center)}]% We know the step
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,3);
\end{tikzpicture}
\end{tabular}

\end{document}

enter image description here

The other one is drawing all by TikZ,

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tabular}{ccccc}
\begin{tikzpicture}[baseline=(current bounding box.center)]
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,1.6);
\begin{scope}[shift={(0.8,0)}]
  \draw[step=0.2cm,gray,very thin] (0,0) grid (3,1.6);  
\end{scope}
\begin{scope}[shift={(4.4,-1.4)}]
  \draw[step=0.2cm,gray,very thin] (0,0) grid (0.2,3);  
\end{scope}
\node at (0.5,0.8) {$=$};
\node at (4.1,0.8) {${\times}$};
\end{tikzpicture}
\end{tabular}

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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