这是长图表的一部分。我不认为我的方法是最好的。请建议如何更好地编程,以便文本不会干扰图表。这是程序
\documentclass{article}
\usepackage{amsmath,tikz}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{hhline}
\begin{document}
\setlength{\arrayrulewidth}{1pt}
\begin{longtable}{|p{7.5cm}p{8cm}|} \hhline{|--|}
\rowcolor{violet!10}\multicolumn{1}{|c}{\textcolor{violet}
{\textbf{Function \& Properties}}}&\multicolumn{1}{c|}
{\textcolor{violet}{\textbf{Graph}}}\\ \hhline{|--|}
%%% Linear Function
\begin{minipage}[b]{.5\textwidth} \normalsize \textbf{Linear
Function} \\
\normalsize $f(x)=mx+b$ \\
($m$ and $b$ are real numbers) \\
\normalsize $\bullet$ Domain and range are all real
numbers\\
\normalsize $\bullet$ Graph is nonvertical line with\\
\normalsize \phantom{$\bullet$}$\text{slope}=m$ and\\
\normalsize \phantom{$\bullet$}$\text{y-intercept}=(0,b)$
\end{minipage}
&
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[scale=1]
%\draw[step=.5cm, dotted, lightgray] (-3.25,-3.5) grid
(3.25,3.5);
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-2.95) node[below]{\phantom{x}} -- (0,3.95)
node[left] {$y$};
% \foreach \x/\xtext in {-3/-6, -2.5/ , -2/-4, -1.5/ ,
-1/-2, -.5/ , .5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
% \draw[xshift=\x cm] (0pt,3pt) -- (0pt,-3pt)
node[below,fill=white]
% {\small $\xtext$};
% \foreach \y/\ytext in {-3.5/ , -3/-6 , -2.5/ ,
-2/-4, -1.5/ , -1/ -2, -.5/ , .5/ , 1/2, 1.5/ ,2/4, 2.5/
, 3/6, 3.5/ }
% \draw[yshift=\y cm] (3pt,0pt) -- (-3pt,0pt)
node[left,fill=white]
% {\small $\ytext$};
%\draw[yshift=-1 cm] (3pt,0pt) -- (-3pt,0pt)
node[left=-4pt,fill=white] {\small $-2$};
\draw[domain=-6:6,smooth,variable=\x,thick,blue,<->] plot
({.5*\x},{.5*(.5*\x+2)});
\draw[fill] (0,1) circle (2pt) node[right] {\small
$(0,b)$};
\node at (0,3.75) [right] {\small \textcolor{red}
{$\mathbf{f(x)=mx+b, m>0\phantom{x}}$}};
\end{tikzpicture}
\end{minipage} \\ \hhline{|--|}
%%% Identity Function
\begin{minipage}[b]{.5\textwidth} \normalsize
\textbf{Identity Function} \\
%\normalsize (special type of linear function) \\
\normalsize $f(x)=x$ (special type of linear function) \\
\normalsize $\bullet$ Domain and range are all real
numbers\\
\normalsize $\bullet$ Graph is a line with slope $m=1$\\
\normalsize \phantom{$\bullet$} and $\text{y-intercept}=
(0,0)$.\\
\normalsize $\bullet$ The line consists of all points for \\
\normalsize \phantom{$\bullet$} which the $x$-coordinate
equals the\\
\normalsize \phantom{$\bullet$} $y$-coordinate.
\end{minipage}
&
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[scale=1]
\draw[step=.5cm, dotted, lightgray] (-3.25,-3.5) grid
(3.25,3.5);
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-3.95) node[below] {\phantom{x}} -- (0,3.95)
node[left] {$y$};
\foreach \x/\xtext in {-3/-6, -2.5/ , -2/-4, -1.5/ , -1/-2, -.5/ , .5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
\draw[xshift=\x cm] (0pt,3pt) -- (0pt,-3pt) node[below,fill=white]
{\small $\xtext$};
\foreach \y/\ytext in {-3.5/ , -3/-6 , -2.5/ , -2/-4, -1.5/ , -1/ -2, -.5/ , .5/ , 1/2, 1.5/ ,2/4, 2.5/ , 3/6, 3.5/ }
\draw[yshift=\y cm] (3pt,0pt) -- (-3pt,0pt) node[left,fill=white]
{\small $\ytext$};
%\draw[yshift=-1 cm] (3pt,0pt) -- (-3pt,0pt) node[left=-4pt,fill=white] {\small $-2$};
\draw[domain=-6:6,smooth,variable=\x,thick,blue,<->] plot ({.5*\x},{.5*(1*\x)});
\draw[fill] (0,0) circle (2pt) node[below right] {\small $(0,0)$};
\draw[fill] (1,1) circle (2pt) node[below right] {\small $(2,2)$};
\draw[fill] (-1,-1) circle (2pt) node[left] {\small $(-2,-2)$};
\node at (0,3.75) [right] {\small \textcolor{red}{$\mathbf{f(x)=x}$}};
\end{tikzpicture}
\end{minipage} \\ \hhline{|--|}
\end{longtable}
\end{document}
输出:
答案1
我想你正在寻找这样的东西:
在您的代码中我做了以下更改:
- 从表中删除
minipage
所有 - 用于
itemize
第一列的列表 - 向
\tikzpicture
我添加选项[baseline=(ny)]
,其中(ny)
是包含 y 轴标签的节点的名称。这样tikzpicture
s 就与单元格顶部对齐 - 稍微改变一下图片的代码
geometry
由于您的表格比文本宽度宽,我通过使用包来更改列宽以及减少页边距
\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{ragged2e}
\usepackage{hhline,longtable}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{%
\setlist[itemize]{leftmargin=*}
}% end of AtBeginEnvironment
\begin{document}
\setlength{\arrayrulewidth}{1pt}
\setlength\extrarowheight{1ex}
\begin{longtable}{|>{\RaggedRight}p{\dimexpr0.45\linewidth-2\tabcolsep-1.5\arrayrulewidth}
|>{\Centering}p{\dimexpr0.55\linewidth-2\tabcolsep-1.5\arrayrulewidth}|
}
\hhline{|--|}
\rowcolor{violet!10}
\multicolumn{1}{|c}{\textcolor{violet}{\textbf{Function \& Properties}}}
& \textcolor{violet}{\textbf{Graph}} \\
\hhline{|--|}
%%% Linear Function
\textbf{Linear Function}
$f(x)=mx+b$ ($m$ and $b$ are real numbers)
\begin{itemize}
\item Domain and range are all real numbers
\item Graph is nonvertical line with $\mathrm{slope}=m$ and $\mathrm{y-intercept}=(0,b)$
\end{itemize}
&
\begin{tikzpicture}[baseline=(ny)]
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-3.25) -- (0,3.50) node[below right,text=red] {$f(x)=mx +b,\ m>0$}
node[left] (ny) {$y$};
\foreach \i/\ii in {-3/-6, -2.5/ , -2/-4, -1.5/ , -1/-2, -.5/ ,
.5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
{
\draw (2pt,\i) -- ++ (-4pt,0) node[fill=white,font=\small,left] {$\ii$};
\draw (\i,2pt) -- ++ (0,-4pt) node[fill=white,font=\small,below] {$\ii$};
}
%
\draw[thick,blue,<->] plot[domain=-6:6] (.5*\x,{.5*(.5*\x+2)});
\fill (0,1) circle[radius=2pt] node[font=\small, below right] {$(0,b)$};
\end{tikzpicture}\smallskip \\
\hhline{|--|}
%%% Identity Function
\textbf{Identity Function}
$f(x)=x$ (special type of linear function)
\begin{itemize}
\item Domain and range are all real numbers
\item Graph is a line with slope $m=1$ and $\mathrm{y-intercept}=
(0,0)$.
\item The line consists of all points for which the $x$-coordinate
equals the $y$-coordinate.
\end{itemize}
&
\begin{tikzpicture}[baseline=(ny)]
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-3.25) -- (0,3.50) node[below right,text=red] {$f(x)=x$}
node[left] (ny) {$y$};
\foreach \i/\ii in {-3/-6, -2.5/ , -2/-4, -1.5/ , -1/-2, -.5/ ,
.5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
{
\draw (2pt,\i) -- ++ (-4pt,0) node[fill=white,font=\small,left] {$\ii$};
\draw (\i,2pt) -- ++ (0,-4pt) node[fill=white,font=\small,below] {$\ii$};
}
%
\draw[thick,blue,<->] plot[domain=-6:6] (.5*\x,{.5*(1*\x)});
\fill (-2,-2) circle[radius=2pt] node[font=\small, below right] {$(-2,-2)$}
( 0, 0) circle[radius=2pt] node[font=\small, below right] {$(0,0)$}
( 2, 2) circle[radius=2pt] node[font=\small, below right] {$(2,2)$};
\end{tikzpicture}\smallskip \\
\hhline{|--|}
\end{longtable}
\end{document}
答案2
这是“最小损害建议”,展示了您可以用 做什么adjustbox
。您可以通过多种方式改进它。但是,这定义了左列和右列的 adustboxes。
\documentclass{article}
\usepackage{amsmath,tikz}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{hhline}
\usepackage{adjustbox}
\begin{document}
\setlength{\arrayrulewidth}{1pt}
\newadjustboxenv{Leftbox}{valign=t,minipage=\the\dimexpr\the\textwidth-8cm-3\tabcolsep,
margin=0pt 0pt 0pt 1ex}
\newadjustboxenv{Rightbox}{valign=t,minipage=8cm}
\begin{longtable}{|p{\the\dimexpr\the\textwidth-8cm-3\tabcolsep}p{8cm}|} \hhline{|--|}
\rowcolor{violet!10}\multicolumn{1}{|c}{\textcolor{violet}
{\textbf{Function \& Properties}}}&\multicolumn{1}{c|}
{\textcolor{violet}{\textbf{Graph}}}\\ \hhline{|--|}
%%% Linear Function
\begin{Leftbox}
\normalsize \textbf{Linear
Function} \\
\normalsize $f(x)=mx+b$ \\
($m$ and $b$ are real numbers) \\
\normalsize $\bullet$ Domain and range are all real
numbers\\
\normalsize $\bullet$ Graph is nonvertical line with\\
\normalsize \phantom{$\bullet$}$\text{slope}=m$ and\\
\normalsize \phantom{$\bullet$}$\text{y-intercept}=(0,b)$
\end{Leftbox}
&
\begin{Rightbox}
\begin{tikzpicture}[scale=1]
%\draw[step=.5cm, dotted, lightgray] (-3.25,-3.5) grid
(3.25,3.5);
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-2.95) node[below]{\phantom{x}} -- (0,3.95)
node[left] {$y$};
% \foreach \x/\xtext in {-3/-6, -2.5/ , -2/-4, -1.5/ , -1/-2, -.5/ , .5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
% \draw[xshift=\x cm] (0pt,3pt) -- (0pt,-3pt) node[below,fill=white]
% {\small $\xtext$};
% \foreach \y/\ytext in {-3.5/ , -3/-6 , -2.5/ , -2/-4, -1.5/ , -1/ -2, -.5/ , .5/ , 1/2, 1.5/ ,2/4, 2.5/ , 3/6, 3.5/ }
% \draw[yshift=\y cm] (3pt,0pt) -- (-3pt,0pt) node[left,fill=white]
% {\small $\ytext$};
%\draw[yshift=-1 cm] (3pt,0pt) -- (-3pt,0pt) node[left=-4pt,fill=white] {\small $-2$};
\draw[domain=-6:6,smooth,variable=\x,thick,blue,<->] plot
({.5*\x},{.5*(.5*\x+2)});
\draw[fill] (0,1) circle (2pt) node[right] {\small
$(0,b)$};
\node at (0,3.75) [right] {\small \textcolor{red}
{$\mathbf{f(x)=mx+b, m>0\phantom{x}}$}};
\end{tikzpicture}
\end{Rightbox} \\ \hhline{|--|}
%%% Identity Function
\begin{Leftbox}
\normalsize
\textbf{Identity Function} \\
%\normalsize (special type of linear function) \\
\normalsize $f(x)=x$ (special type of linear function) \\
\normalsize $\bullet$ Domain and range are all real
numbers\\
\normalsize $\bullet$ Graph is a line with slope $m=1$\\
\normalsize \phantom{$\bullet$} and $\text{y-intercept}=
(0,0)$.\\
\normalsize $\bullet$ The line consists of all points for \\
\normalsize \phantom{$\bullet$} which the $x$-coordinate
equals the\\
\normalsize \phantom{$\bullet$} $y$-coordinate.
\end{Leftbox}
&
\begin{Rightbox}
\begin{tikzpicture}[scale=1]
\draw[step=.5cm, dotted, lightgray] (-3.25,-3.5) grid
(3.25,3.5);
\draw[->] (-3.75,0) -- (3.75,0) node[below] {$x$};
\draw[->] (0,-3.95) node[below] {\phantom{x}} -- (0,3.95)
node[left] {$y$};
\foreach \x/\xtext in {-3/-6, -2.5/ , -2/-4, -1.5/ , -1/-2, -.5/ , .5/ , 1/2, 1.5/ , 2/4 , 2.5/ , 3/6}
\draw[xshift=\x cm] (0pt,3pt) -- (0pt,-3pt) node[below,fill=white]
{\small $\xtext$};
\foreach \y/\ytext in {-3.5/ , -3/-6 , -2.5/ , -2/-4, -1.5/ , -1/ -2, -.5/ , .5/ , 1/2, 1.5/ ,2/4, 2.5/ , 3/6, 3.5/ }
\draw[yshift=\y cm] (3pt,0pt) -- (-3pt,0pt) node[left,fill=white]
{\small $\ytext$};
%\draw[yshift=-1 cm] (3pt,0pt) -- (-3pt,0pt) node[left=-4pt,fill=white] {\small $-2$};
\draw[domain=-6:6,smooth,variable=\x,thick,blue,<->] plot ({.5*\x},{.5*(1*\x)});
\draw[fill] (0,0) circle (2pt) node[below right] {\small $(0,0)$};
\draw[fill] (1,1) circle (2pt) node[below right] {\small $(2,2)$};
\draw[fill] (-1,-1) circle (2pt) node[left] {\small $(-2,-2)$};
\node at (0,3.75) [right] {\small \textcolor{red}{$\mathbf{f(x)=x}$}};
\end{tikzpicture}
\end{Rightbox} \\ \hhline{|--|}
\end{longtable}
\end{document}