我正在尝试将 TikZ 图片向上移动,以便消除解决方案占用的空间。我怎样才能将 TikZ 图片向上移动(一点点)进入对齐环境?仅供参考,以下是考试问题。
“从 $(-2,1)$ 到点 $P$ 的线段中点是 $(1, -1)$。确定 $P$ 的坐标。”
以下是我对考试问题的解答。
Let $P = (x,y)$. We need to find $x$ and $y$. We have
\begin{align*}
\text{Midpoint} = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)
\quad &\implies \quad
(1,-1) = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)\\
&\implies \quad
\begin{dcases}
1 = \frac{-2 + x}{2}\\
-1 = \frac{1 + y}{2}
\end{dcases}\\
&\implies \quad
\begin{dcases}
2 = -2 + x\\
-2 = 1 + y
\end{dcases}
\quad \implies \quad
\begin{dcases}
x = 4\\
y = -3.
\end{dcases}
\end{align*}
%\begin{minipage}[t]{5cm}{ %DO I NEED THIS?
\begin{tikzpicture}[>=latex',scale=0.5]
% Draw grid lines
\draw[help lines] (-2.5,-3.5) grid (4.5,1.5);
% Draw x-axis
\draw[very thick,->] (-3,0) -- (5.5,0)
node[right] {\large $x$};
% Draw y-axis
\draw[very thick, ->] (0,-4) -- (0,2.5)
node[above] {\large $y$};
% Special points
\node[above, fill=SolutionColor] at (-2,1) {$(-2,1)$};
\fill (-2,1) circle (4pt);
\node[right, fill=SolutionColor] at (1.5,-1) {$(1,-1)$};
\fill (1,-1) circle (4pt);
\node[right, fill=SolutionColor] at (4,-3) {$P$};
\draw (-2,1) -- (1,-1) -- (4,-3);
\fill[red] (4,-3) circle (4pt);
\end{tikzpicture}
%\end{minipage}% DO I NEED THIS?
答案1
这是 Martin Scharrer 的优秀软件包所要做的工作adjustbox
:它允许(在许多其他事情中)修剪一个盒子的顶部(该盒子可以包含许多其他东西,其中包括tikzpicture
),因此它的官方高度小于内容的实际高度。
如果你把你的包裹起来tikzpicture
,\begin{adjustbox}{trim=0 0 0 2.5cm} ... \end{adjustbox}
你会得到
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{adjustbox}
\begin{document}
Let $P = (x,y)$. We need to find $x$ and $y$. We have
\begin{align*}
\text{Midpoint} = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)
\quad &\implies \quad
(1,-1) = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)\\
&\implies \quad
\begin{dcases}
1 = \frac{-2 + x}{2}\\
-1 = \frac{1 + y}{2}
\end{dcases}\\
&\implies \quad
\begin{dcases}
2 = -2 + x\\
-2 = 1 + y
\end{dcases}
\quad \implies \quad
\begin{dcases}
x = 4\\
y = -3.
\end{dcases}
\end{align*}
\begin{adjustbox}{trim=0 0 0 2.5cm}%
\begin{tikzpicture}[>=latex',scale=0.5]
% Draw grid lines
\draw[help lines] (-2.5,-3.5) grid (4.5,1.5);
% Draw x-axis
\draw[very thick,->] (-3,0) -- (5.5,0)
node[right] {\large $x$};
% Draw y-axis
\draw[very thick, ->] (0,-4) -- (0,2.5)
node[above] {\large $y$};
% Special points
\node[above, fill=white] at (-2,1) {$(-2,1)$};
\fill (-2,1) circle (4pt);
\node[right, fill=white] at (1.5,-1) {$(1,-1)$};
\fill (1,-1) circle (4pt);
\node[right, fill=white] at (4,-3) {$P$};
\draw (-2,1) -- (1,-1) -- (4,-3);
\fill[red] (4,-3) circle (4pt);
\end{tikzpicture}
\end{adjustbox}
\end{document}
答案2
可以使用\useasboundingbox
。您需要找到矩形的尺寸才能正确放置图片。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
Let $P = (x,y)$. We need to find $x$ and $y$. We have
\begin{align*}
\text{Midpoint} = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)
\quad &\implies \quad
(1,-1) = \biggl( \frac{-2 + x}{2} , \frac{1 + y}{2} \biggr)\\
\begin{tikzpicture}[>=latex',scale=0.5]
\useasboundingbox (0,0) rectangle (7,3);
% Draw grid lines
\draw[help lines] (-2.5,-3.5) grid (4.5,1.5);
% Draw x-axis
\draw[very thick,->] (-3,0) -- (5.5,0)
node[right] {\large $x$};
% Draw y-axis
\draw[very thick, ->] (0,-4) -- (0,2.5)
node[above] {\large $y$};
% Special points
\node[above, fill=white] at (-2,1) {$(-2,1)$};
\fill (-2,1) circle (4pt);
\node[right, fill=white] at (1.5,-1) {$(1,-1)$};
\fill (1,-1) circle (4pt);
\node[right, fill=white] at (4,-3) {$P$};
\draw (-2,1) -- (1,-1) -- (4,-3);
\fill[red] (4,-3) circle (4pt);
\end{tikzpicture} &\implies \quad
\begin{dcases}
1 = \frac{-2 + x}{2}\\
-1 = \frac{1 + y}{2}
\end{dcases}\\
&\implies \quad
\begin{dcases}
2 = -2 + x\\
-2 = 1 + y
\end{dcases}
\quad \implies \quad
\begin{dcases}
x = 4\\
y = -3.
\end{dcases}
\end{align*}
\end{document}