我怎样才能将文本和 tikzpicture 适当地放置在图形略低于文本标题的位置?
\documentclass{article}
\usepackage{tikz}
\usepackage{geometry}
\begin{document}
\begin{minipage}[t]{.5\linewidth}
\textcolor{red}{{\bf \Large Ordered Pairs and Graphs}}\\
Each point in a plane corresponds to an ordered pair of numbers. Note in the
figure below that the point corresponding to the pair $(2,5)$ is different from
the point corresponding to the pair $(5,2)$. This is why we call a pair like
$(2,5)$ an \emph{ordered pair}. The first number is called the \emph{first
coordinate} of the point, and the second number is called the \emph{second
coordinate}. Together these are the \emph{coordinates of the point}. The
horizontal line is often labeled as the \emph{$x$-axis}, and the vertical line
is often labeled as the \emph{$y$-axis}. The two axes intersect at the
\emph{origin}, $(0,0)$.
\end{minipage}
\begin{tikzpicture}[scale=.6,cap=round]
\tikzstyle{axes}=[]
% The graphic
\draw[style=help lines,step=1cm, dotted] (-6.9,-6.9) grid (6.9,6.9);
\begin{scope}[style=axes]
\draw[->] (-6.9,0) -- (6.9,0) node[right] {$x$};
\draw[->] (0,-6.9) -- (0,6.9) node[above] {$y$};
\foreach \x/\xtext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white]
{\tiny $\xtext$};
\foreach \y/\ytext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white]
{\tiny $\ytext$};
\end{scope}
\end{tikzpicture}
\end{document}
答案1
标准程序是将 tikzpicture 放入第二个小页面,相对对齐已经讨论了很多次这里. 这很可能就是您想要走的路。
但是,您也有可能选择不同的方式,并真正希望将图片与标题相关联。在这种情况下,您可以加载库tikzmark
并将图片作为覆盖层放置。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{geometry}
\begin{document}
\begin{minipage}[t]{.5\linewidth}
\textcolor{red}{\bfseries\Large Ordered Pairs and Graphs}\hfill
\tikzmarknode{X}{\phantom{X}}\\
Each point in a plane corresponds to an ordered pair of numbers. Note in the
figure below that the point corresponding to the pair $(2,5)$ is different from
the point corresponding to the pair $(5,2)$. This is why we call a pair like
$(2,5)$ an \emph{ordered pair}. The first number is called the \emph{first
coordinate} of the point, and the second number is called the \emph{second
coordinate}. Together these are the \emph{coordinates of the point}. The
horizontal line is often labeled as the \emph{$x$-axis}, and the vertical line
is often labeled as the \emph{$y$-axis}. The two axes intersect at the
\emph{origin}, $(0,0)$.
\end{minipage}
\begin{tikzpicture}[scale=.6,cap=round,overlay,remember picture,
shift={([xshift=7cm,yshift=-7cm]X.south east)}]
\tikzset{axes/.style={}}
% The graphic
\draw[style=help lines,step=1cm, dotted] (-6.9,-6.9) grid (6.9,6.9);
\begin{scope}[style=axes]
\draw[->] (-6.9,0) -- (6.9,0) node[right] {$x$};
\draw[->] (0,-6.9) -- (0,6.9) node[above] {$y$};
\foreach \x/\xtext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white]
{\tiny $\xtext$};
\foreach \y/\ytext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white]
{\tiny $\ytext$};
\end{scope}
\end{tikzpicture}
\end{document}
我绝对不是说这比使用 minipages“更好”。这只是一种替代方案,如果您在使用其他方法时遇到问题,可以尝试一下。
附录:首次尝试添加正确数量的垂直空间。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\usepackage{geometry}
\begin{document}
\begin{minipage}[t]{.5\linewidth}
\textcolor{red}{\bfseries\Large Ordered Pairs and Graphs}\hfill
\tikzmarknode{X}{\phantom{X}}\\
Each point in a plane corresponds to an ordered pair of numbers. Note in the
figure below that the point corresponding to the pair $(2,5)$ is different from
the point corresponding to the pair $(5,2)$. This is why we call a pair like
$(2,5)$ an \emph{ordered pair}. The first number is called the \emph{first
coordinate} of the point, and the second number is called the \emph{second
coordinate}. Together these are the \emph{coordinates of the point}. The
horizontal line is often labeled as the \emph{$x$-axis}, and the vertical line
is often labeled as the \emph{$y$-axis}. The two axes intersect at the
\emph{origin}, $(0,0)$.\tikzmarknode{Y}{\phantom{Y}}
\end{minipage}
\begin{tikzpicture}[scale=.6,cap=round,overlay,remember picture,
shift={([xshift=7cm,yshift=-7cm]X.south east)}]
\tikzset{axes/.style={}}
% The graphic
\draw[style=help lines,step=1cm, dotted] (-6.9,-6.9) grid (6.9,6.9);
\begin{scope}[style=axes]
\draw[->] (-6.9,0) -- (6.9,0) node[right] {$x$};
\draw[->] (0,-6.9)coordinate(S) -- (0,6.9) node[above] {$y$};
\foreach \x/\xtext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white]
{\tiny $\xtext$};
\foreach \y/\ytext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white]
{\tiny $\ytext$};
\end{scope}
\path let \p1=($(Y.south)-(S)$),\n1={0.5*\y1} in \pgfextra{\xdef\myspace{\n1}
\typeout{\myspace}};
\end{tikzpicture}\\[\myspace]
Some more text
\end{document}
答案2
这里有两种可能的解决方案:一个使用\raisebox{-\height}{tikzpicture}
,另一个使用普通的 TeX 宏包insbox
:
\documentclass{article}
\usepackage{tikz}
\input{insbox}
\makeatletter\@InsertBoxMargin = 3mm
\makeatother
\usepackage[showframe]{geometry}
\begin{document}
\noindent\begin{minipage}[t]{.4\linewidth}
\textcolor{red}{{\bfseries \Large Ordered Pairs and Graphs}}\\
Each point in a plane corresponds to an ordered pair of numbers. Note in the
figure below that the point corresponding to the pair $(2,5)$ is different from
the point corresponding to the pair $(5,2)$. This is why we call a pair like
$(2,5)$ an \emph{ordered pair}. The first number is called the \emph{first
coordinate} of the point, and the second number is called the \emph{second
coordinate}. Together these are the \emph{coordinates of the point}. The
horizontal line is often labeled as the \emph{$x$-axis}, and the vertical line
is often labeled as the \emph{$y$-axis}. The two axes intersect at the
\emph{origin}, $(0,0)$.
\end{minipage}
\quad
\raisebox{-\height}{\begin{tikzpicture}[scale=.6,cap=round]
\tikzstyle{axes}=[]
% The graphic
\draw[style=help lines,step=1cm, dotted] (-6.9,-6.9) grid (6.9,6.9);
\begin{scope}[style=axes]
\draw[->] (-6.9,0) -- (6.9,0) node[right] {$x$};
\draw[->] (0,-6.9) -- (0,6.9) node[above] {$y$};
\foreach \x/\xtext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white]
{\tiny $\xtext$};
\foreach \y/\ytext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white]
{\tiny $\ytext$};
\end{scope}
\end{tikzpicture}}
\newpage
\InsertBoxR{1}{\begin{tikzpicture}[scale=.6,cap=round]
\tikzstyle{axes}=[]
% The graphic
\draw[style=help lines,step=1cm, dotted] (-6.9,-6.9) grid (6.9,6.9);
\begin{scope}[style=axes]
\draw[->] (-6.9,0) -- (6.9,0) node[right] {$x$};
\draw[->] (0,-6.9) -- (0,6.9) node[above] {$y$};
\foreach \x/\xtext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white]
{\tiny $\xtext$};
\foreach \y/\ytext in {-6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white]
{\tiny $\ytext$};
\end{scope}
\end{tikzpicture}}
\noindent\textcolor{red}{{\bfseries \Large Ordered Pairs and Graphs}}\\
Each point in a plane corresponds to an ordered pair of numbers. Note in the
figure below thatthe point corresponding to the pair $(2,5)$ is different from
the point corresponding to the pair $(5,2)$. This is why we call a pair like
$(2,5)$ an \emph{ordered pair}. The first number is called the \emph{first
coordinate} of the point, and the second number is called the \emph{second
coordinate}. Together these are the \emph{coordinates of the point}. The
horizontal line is often labeled as the \emph{$x$-axis}, and the vertical line
is often labeled as the \emph{$y$-axis}. The two axes intersect at the
\emph{origin}, $(0,0)$.
\end{document}