水平对齐小页面不起作用

水平对齐小页面不起作用

我试图将这两个小页面对齐到顶部,但是不起作用.....有人可以帮忙吗?

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}

\begin{document}
\begin{minipage}[t]{0.3\textwidth}
$2+2=4$
\end{minipage}
\begin{minipage}[t]{0.3\textwidth}
\begin{tikzpicture}
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{minipage}
\end{document}

它给了我这个: enter image description here

我要这个: enter image description here

我怎样才能得到它???

答案1

问题在于tikzpicture基线的位置(位于圆的中间)。您应该相应地移动它。最简单的方法似乎是将图像封闭在里面。如果使用adjustbox两个环境,您会获得更短的代码。但是,与结合使用:minipagetabularadjustboxminipage

\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}

\begin{document}
\centering
   \begin{tabular}{|p{0.25\linewidth}|p{0.5\linewidth}|}
$2+2=4$
&
\adjustbox{valign=t}{\begin{tikzpicture}% adjustbox move tikzpicture baseline to the top of tabular cell
\draw (0,0) circle (3cm);
\end{tikzpicture}}
    \end{tabular}
\end{document}

或者

\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}

\begin{document}
\centering
   \begin{minipage}[t]{0.25\linewidth}
$2+2=4$
    \end{minipage}
\adjustbox{valign=t}{\begin{tikzpicture}% adjustbox move tikzpicture baseline to the line in in minipage
\draw (0,0) circle (3cm);
\end{tikzpicture}}
 \end{document}

enter image description here

相关内容