使用 tikzpicture 进行垂直对齐

使用 tikzpicture 进行垂直对齐

tabular我在具有 的环境中遇到了垂直对齐问题tikzpicture

我目前的代码是:

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

结果是: 在此处输入图片描述

但我想要的更像是这样的: 在此处输入图片描述

我该怎么做?

答案1

您可以将baseline选项用于您的tikzpictures。(使用$\ast$而不是普通的*来调整基线)

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

在此处输入图片描述

答案2

一种方法是设置baseline环境的密钥

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

在此处输入图片描述

另一个是用 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}

在此处输入图片描述

相关内容