将 TikZ 环境与 minipage 环境对齐

将 TikZ 环境与 minipage 环境对齐

我有一个TikZ环境和一个minipage环境,我想让它们在顶部对齐。我使用baseline=(current bounding box.north)带有环境的选项,以及带有环境的TikZ选项。两个环境的显示不对齐。[t]minipage

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections,quotes,decorations.markings,decorations.pathreplacing}


\begin{document}


\noindent \begin{minipage}[t]{3.75in}
\raggedright{$\triangle\mathit{ABC}$ is a right triangle, and its right angle is at $C$. $\mathit{CP}$ is an altitude of it. What is the value of $x - y$?}
\begin{tabbing}
\hspace*{3em} \= \kill
\> \textbf{a.) }$-30$ \\
\> \textbf{b.) }$-15$ \\
\> \textbf{c.) }0 \\
\> \textbf{d.) }15 \\
\> \textbf{e.) }30
\end{tabbing}
\end{minipage}
%
\hspace{-1.5cm}
%
\begin{tikzpicture}[baseline=(current bounding box.north)]

\coordinate (A) at (0,0);
\coordinate (C) at (5,2);

%B is the intersection of the line through C that is perpendicular to $\overline{AC}$ and
%the line through A inclined at an angle of 30 degrees.
\path[name path=a_line_through_A_to_locate_B] (A) -- ($(A) +(-15:7)$);
\path[name path=a_line_through_C_perpendicular_to_AC_to_locate_B] (C) -- ($(C)!4.5cm!90:(A)$);
\coordinate[name intersections={of=a_line_through_A_to_locate_B and a_line_through_C_perpendicular_to_AC_to_locate_B, by=B}];
\draw (A) -- (B) -- (C) -- cycle;


%A right-angle mark is drawn at C.
\coordinate (U) at ($(C)!4mm!-45:(B)$);
\draw (U) -- ($(C)!(U)!(B)$);
\draw (U) -- ($(C)!(U)!(A)$);


\coordinate (P) at ($(A)!(C)!(B)$);
\draw (C) -- (P);

%A right-angle mark is drawn at P.
\coordinate (V) at ($(P)!4mm!-45:(A)$);
\draw (V) -- ($(P)!(V)!(A)$);
\draw (V) -- ($(P)!(V)!(C)$);


%The labels for A, B, and C are typeset.
\node (label_for_A) at ($(A)!3mm!-90:(B)$){$A$};
\node (label_for_B) at ($(B)!3mm!90:(A)$){$B$};
\node (label_for_P) at ($(P)!3mm!-90:(B)$){$P$};
\node (label_for_C) at ($(C)!-3mm!(P)$){$C$};



%The angle at A is labeled x.
\draw[blue] let \p1=($(A)-(C)$), \n1={atan(\y1/\x1)} in (-15:0.5) arc (-15:\n1:0.5);
\draw let \p1=($(A)-(C)$), \n1={atan(\y1/\x1)} in node[font=\footnotesize, anchor={0.5*(\n1-15)-180}] at ({0.5*(\n1-15)}:0.5){$x$};

%An angle at C is labeled y.
\draw[blue] let \p1=($(C)-(P)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(B)$), \n2={atan(\y2/\x2)} in ($(C) +({\n1-180}:0.5)$) arc ({\n1-180}:\n2:0.5);
\draw let \p1=($(C)-(P)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(B)$), \n2={atan(\y2/\x2)} in node[font=\footnotesize, anchor={0.5*(\n1-180+\n2)-180}] at ($(C) +({0.5*(\n1-180+\n2)}:0.5)$){$y$};

\end{tikzpicture}
\end{document}

答案1

在 tikzpicture 末尾添加以下行:

\draw (current bounding box.south west) rectangle (current bounding box.north east);

显示图片的边界框:

结果

可以发现两个问题:

  1. 图中标签 $C$ 上方有一点空白。如果您使用[inner sep=0pt]节点,则可以将其删除(label_for_C)
  2. 更重要的是,选项[t]不会minipage将内容对齐到小页面“边界框”的顶部,而是对齐到其顶行的基线。这可以通过一个小技巧来解决:将其添加\vskip0pt为小页面的第一个内容。这样,框的第一个“行”就是空的,您就可以获得正确的对齐方式。

使用这两个技巧,结果是:

结果2

现在我们可以移除框架:

最后结果

相关内容