我在下面代码中使用了 scale 选项,期望使在“图1”和“图2”对齐的前提下,尽量使图和表一样大。不过若采取这种方式,那么遇到这种情况将不断调试 scale 的值,这显然不优雅。希望能得到一个通用的解决办法。
\documentclass[UTF8]{ctexart}
\usepackage{tikz,tabularray,amsmath,showframe}
\begin{document}
\begin{center}
\zihao{-6}
\begin{minipage}{.5\linewidth}
\centering
\begin{tblr}{baseline=c,columns={c,m},hlines,vlines}
级数 & 名称 & {风速大小\\(单位: $\mathrm{m/s}$)}\\
2 & 轻风 & $1.6\,\text{{}\~{}}\,3.3$ \\
3 & 微风 & $3.4\,\text{{}\~{}}\,5.4$ \\
4 & 和风 & $5.5\,\text{{}\~{}}\,7.9$ \\
5 & 劲风 & $8.0\,\text{{}\~{}}\,10.7$ \\
\end{tblr}\\[1ex]图1
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\begin{tikzpicture}[baseline={(current bounding box.center)},scale=.6875]
\draw[dash pattern=on 2pt off 2pt,gray]
(0,0) grid (3,3);
\draw[-stealth] (-.5,0) -- (3.5,0);
\draw[-stealth] (0,-.5) -- (0,3.5);
\draw[-stealth] (3,3) -- (0,2);
\draw[-stealth] (2,0) -- (3,3);
\foreach \x in {1,2,3} {
\node at (\x,0) [below] {$\x$};
\node at (0,\x) [left] {$\x$};}
\node at (0,0) [below left] {$O$};
\node at (3.5,0) [below] {$x$\vphantom{123}};
\node at (0,3.5) [left] {$y$};
\node at (1,3) [below] {视风风速};
\node at (2.5,0) [above] {船速};
\end{tikzpicture}\\[1ex]图2
\end{minipage}
\end{center}
\end{document}
\documentclass[fontset=fandol]{ctexart}
\usepackage{tikz,tabularray,amsmath,graphicx,showframe}
\begin{document}
\begin{center}
\zihao{-6}
\begin{minipage}{.5\linewidth}
\centering
\begin{tblr}{baseline=c,columns={c,m},hlines,vlines}
级数 & 名称 & {风速大小\\(单位: $\mathrm{m/s}$)}\\
2 & 轻风 & $1.6\,\text{{}\~{}}\,3.3$ \\
3 & 微风 & $3.4\,\text{{}\~{}}\,5.4$ \\
4 & 和风 & $5.5\,\text{{}\~{}}\,7.9$ \\
5 & 劲风 & $8.0\,\text{{}\~{}}\,10.7$ \\
\end{tblr}\\[1ex]图1
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\begin{tikzpicture}[baseline={(current bounding box.center)},scale=.6875]
\draw[dash pattern=on 2pt off 2pt,gray] (0,0) grid (3,3);
\draw[-stealth] (-.5,0) -- (3.5,0);
\draw[-stealth] (0,-.5) -- (0,3.5);
\draw[-stealth] (3,3) -- (0,2);
\draw[-stealth] (2,0) -- (3,3);
\foreach \x in {1,2,3} {
\node at (\x,0) [below] {$\x$};
\node at (0,\x) [left] {$\x$};
}
\node at (0,0) [below left] {$O$};
\node at (3.5,0) [below] {$x$};
\node at (0,3.5) [left] {$y$};
\node at (1,3) [below] {视风风速};
\node at (2.5,0) [above] {船速};
\end{tikzpicture}\\[1ex]图2
\end{minipage}
\end{center}
\bigskip
\newsavebox{\tmpbox}
\newcommand{\matchtmpboxdepth}[1]{%
\raisebox{-\dp\tmpbox}{#1}%
}
\begin{lrbox}{\tmpbox}%
\zihao{-6}%
\begin{tblr}{baseline=c,columns={c,m},hlines,vlines}
级数 & 名称 & {风速大小\\(单位: $\mathrm{m/s}$)}\\
2 & 轻风 & $1.6\,\text{{}\~{}}\,3.3$ \\
3 & 微风 & $3.4\,\text{{}\~{}}\,5.4$ \\
4 & 和风 & $5.5\,\text{{}\~{}}\,7.9$ \\
5 & 劲风 & $8.0\,\text{{}\~{}}\,10.7$ \\
\end{tblr}%
\end{lrbox}
\begin{center}
\zihao{-6}
\begin{minipage}{.5\linewidth}
\centering
\usebox{\tmpbox}\\[1ex]图1%
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\matchtmpboxdepth{%
\resizebox{!}{\dimexpr\ht\tmpbox+\dp\tmpbox\relax}{%
\begin{tikzpicture}
\draw[dash pattern=on 2pt off 2pt,gray] (0,0) grid (3,3);
\draw[-stealth] (-.5,0) -- (3.5,0);
\draw[-stealth] (0,-.5) -- (0,3.5);
\draw[-stealth] (3,3) -- (0,2);
\draw[-stealth] (2,0) -- (3,3);
\foreach \x in {1,2,3} {
\node at (\x,0) [below] {$\x$};
\node at (0,\x) [left] {$\x$};
}
\node at (0,0) [below left] {$O$};
\node at (3.5,0) [below] {$x$};
\node at (0,3.5) [left] {$y$};
\node at (1,3) [below] {视风风速};
\node at (2.5,0) [above] {船速};
\draw[red, dashed, thick, overlay]
([xshift=.5\pgflinewidth,yshift=.5\pgflinewidth]current bounding box.south west) rectangle
([xshift=-.5\pgflinewidth,yshift=-.5\pgflinewidth]current bounding box.north east);
\end{tikzpicture}
}}\\[1ex]图2
\end{minipage}
\end{center}
\begin{center}
\zihao{-6}
\begin{minipage}{.5\linewidth}
\centering
\usebox{\tmpbox}\\[1ex]图1%
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\matchtmpboxdepth{%
\includegraphics[height=\dimexpr\ht\tmpbox+\dp\tmpbox\relax]{example-image-duck}%
}
\\[1ex]图2
\end{minipage}
\end{center}
\end{document}
真实的题目排版里是不是也不是非要「严格对齐」不可呢?考虑到代码的可读性,直接用例如scale=0.65我个人觉得也是合适的。
Edited
下面的代码用
tblr简化了两个minipage的控制,代码可读性是比「严格同高对齐」高的BTW...为什么标记标签为「浮动体」 代码里似乎没有任何浮动的对象