在文本右侧显示 TikZ 图表

在文本右侧显示 TikZ 图表

我有一个矩形图形,要显示在描述它的某些文本的右侧。目前,矩形大部分位于文本上方(以及文本的右侧)。我猜将顶部顶点与包含文本的框的顶部边缘对齐是合适的。

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

\usepackage{tikz}
\usetikzlibrary{calc}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

\begin{document}

\noindent
\begin{minipage}{4.75in}
\noindent {\textbf{1.) }}The area of a rectangle is 168 square inches, and its perimeter is 62 inches. What is the product of the magnitudes of its diagonals?
\begin{tabbing}
\hspace*{3em} \= \hspace{2.5in} \= \kill
\> {\textbf{a.) }}625   \> {\textbf{b.) }}300 \\
\> {\textbf{c.) }}200   \> {\textbf{d.) }}150 \\
\> {\textbf{e.) }}125
\end{tabbing}
\end{minipage}
\begin{tikzpicture}

%Vertices A, B, C, and D are located.
\path (0,0) coordinate (A) (20:{7/8}) coordinate (B) ($(B) +(110:3)$) coordinate (C) ($(C) +(-160:{7/8})$) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;

%The diagonals are drawn.
\draw[dashed] (A) -- (C);
\draw[dashed] (B) -- (D);


%The length and width of the rectangle are typeset.
\node[anchor={20+90}, inner sep=0, font=\footnotesize] at ($($(A)!1.5mm!-90:(B)$)!0.5!($(B)!1.5mm!90:(A)$)$){$w$};
\node[anchor={110+90}, inner sep=0, font=\footnotesize] at ($($(B)!1.5mm!-90:(C)$)!0.5!($(C)!1.5mm!90:(B)$)$){$\ell$};

\end{tikzpicture}

\end{document}

答案1

要将小页面的顶部与 tikzpicture 的顶部对齐,请使用:

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

\usepackage{tikz}
\usetikzlibrary{calc}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

\begin{document}

\noindent
\begin{minipage}[t]{4.75in}
\noindent {\textbf{1.) }}The area of a rectangle is 168 square inches, and its perimeter is 62 inches. What is the product of the magnitudes of its diagonals?
\begin{tabbing}
\hspace*{3em} \= \hspace{2.5in} \= \kill
\> {\textbf{a.) }}625   \> {\textbf{b.) }}300 \\
\> {\textbf{c.) }}200   \> {\textbf{d.) }}150 \\
\> {\textbf{e.) }}125
\end{tabbing}
\end{minipage}
\begin{tikzpicture}[baseline=(current bounding box.north)]

%Vertices A, B, C, and D are located.
\path (0,0) coordinate (A) (20:{7/8}) coordinate (B) ($(B) +(110:3)$) coordinate (C) ($(C) +(-160:{7/8})$) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;

%The diagonals are drawn.
\draw[dashed] (A) -- (C);
\draw[dashed] (B) -- (D);


%The length and width of the rectangle are typeset.
\node[anchor={20+90}, inner sep=0, font=\footnotesize] at ($($(A)!1.5mm!-90:(B)$)!0.5!($(B)!1.5mm!90:(A)$)$){$w$};
\node[anchor={110+90}, inner sep=0, font=\footnotesize] at ($($(B)!1.5mm!-90:(C)$)!0.5!($(C)!1.5mm!90:(B)$)$){$\ell$};

\end{tikzpicture}

\end{document}

结盟


实际上,这会将 tikzpicture 的顶部与 的底部对齐1)。要与 的顶部对齐,请1)添加类似

\path (current bounding box.north) ++(0,-.6\baselineskip) coordinate (align);

并且[baseline=(align)] 还可以使用\raisebox{0.6\baselineskip}{...}

答案2

在小页面中添加 [b] 选项

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calc}


\begin{document}

\noindent
\begin{minipage}[b]{4.75in}
\noindent {\textbf{1.) }}The area of a rectangle is 168 square inches, and its perimeter is 62 inches. What is the product of the magnitudes of its diagonals?
\begin{tabbing}
\hspace*{3em} \= \hspace{2.5in} \= \kill
\> {\textbf{a.) }}625   \> {\textbf{b.) }}300 \\
\> {\textbf{c.) }}200   \> {\textbf{d.) }}150 \\
\> {\textbf{e.) }}125
\end{tabbing}
\end{minipage}
\begin{minipage}[b]{2in}
\begin{tikzpicture}

%Vertices A, B, C, and D are located.
\path (0,0) coordinate (A) (20:{7/8}) coordinate (B) ($(B) +(110:3)$) coordinate (C) ($(C) +(-160:{7/8})$) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;

%The diagonals are drawn.
\draw[dashed] (A) -- (C);
\draw[dashed] (B) -- (D);


%The length and width of the rectangle are typeset.
\node[anchor={20+90}, inner sep=0, font=\footnotesize] at ($($(A)!1.5mm!-90:(B)$)!0.5!($(B)!1.5mm!90:(A)$)$){$w$};
\node[anchor={110+90}, inner sep=0, font=\footnotesize] at ($($(B)!1.5mm!-90:(C)$)!0.5!($(C)!1.5mm!90:(B)$)$){$\ell$};

\end{tikzpicture}
\end{minipage}

\end{document}

事实上,我不喜欢这些带有 minipages 的布局,因此直接使用 tikz 通过调整节点的位置来实现

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calc,positioning}

\begin{document}


\begin{tikzpicture}
\node(fig){\begin{tikzpicture}
%Vertices A, B, C, and D are located.
\path (0,0) coordinate (A) (20:{7/8}) coordinate (B) ($(B) +(110:3)$) coordinate (C) ($(C) +(-160:{7/8})$) coordinate (D);
\draw (A) -- (B) -- (C) -- (D) -- cycle;

%The diagonals are drawn.
\draw[dashed] (A) -- (C);
\draw[dashed] (B) -- (D);


%The length and width of the rectangle are typeset.
\node[anchor={20+90}, inner sep=0, font=\footnotesize] at ($($(A)!1.5mm!-90:(B)$)!0.5!($(B)!1.5mm!90:(A)$)$){$w$};
\node[anchor={110+90}, inner sep=0, font=\footnotesize] at ($($(B)!1.5mm!-90:(C)$)!0.5!($(C)!1.5mm!90:(B)$)$){$\ell$};

\end{tikzpicture}};
\node[below left =0em of fig.north west, text width=4.75in]{
\noindent {\textbf{1.) }}The area of a rectangle is 168 square inches, and its perimeter is 62 inches. What is the product of the magnitudes of its diagonals?
\begin{tabbing}
\hspace*{3em} \= \hspace{2.5in} \= \kill
\> {\textbf{a.) }}625   \> {\textbf{b.) }}300 \\
\> {\textbf{c.) }}200   \> {\textbf{d.) }}150 \\
\> {\textbf{e.) }}125
\end{tabbing}
};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容