Tikz 图片之间的 Tikz 对齐

Tikz 图片之间的 Tikz 对齐

我正在尝试将这两个图形与 x 轴对齐。我尝试过迷你页面,但没有成功。我也尝试过操作 ( \myplotB),但失败了。我到处找了找。任何帮助我都感激不尽。

\usepackage[margin=.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns,angles,quotes,shadings,arrows.meta}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage{multicol}
\pgfplotsset{every x tick label/.append style={font=\footnotesize, yshift=0.6ex}}
\pgfplotsset{every y tick label/.append style={font=\footnotesize, xshift=0.5ex}}

\newcommand{\myplotB}[1]{
\begin{tikzpicture}
\draw[-Triangle] (-2,0)--(2,0);
\draw[Triangle-] (0,2)--(0,-2);
\node[below] at (2,0){$x$};
\node[above] at (0,2){$y$};
\node[below right] at (1,0){\footnotesize{1}};
\draw (0,0) circle [radius=1cm];
\end{tikzpicture}\hspace{.5in}
}

\begin{document}

\section*{Graphing Cosine Functions}
\noindent\rule{15cm}{0.4pt}

The function $y=A\cos t +k$ have \textbf{amplitude} $|A|$ and their \`textbf`{midline} is the horizontal line $y=k$


\begin{tikzpicture}
\begin{axis}[
grid style={blue!50},
axis x line = center,
axis y line = center,
xlabel style={above right},
ylabel style={above right},
xlabel={$x$}, ylabel={$y$},
xtick = {-1.5707, 0, ..., 6.28318},
xmin = -2,   xmax =6.28318,
ymin = -3,   ymax = 3,
ytick = {-3,-2,...,3},
xticklabels = {$-\frac{\pi}{2}$, 0, 
    $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$},
grid  = both,
]
\addplot[samples=300,domain=0:6.28318,color=red] {cos(deg(x))}; 
\filldraw[red] (0,1) circle (3pt) node at (0,1){};
\end{axis}
\end{tikzpicture}
\qquad
\myplotB

\end{document}

答案1

s的垂直对齐tikzpicture可以通过选项实现baseline:通过baseline=0强制图片 x 轴与周围文本的基线对齐,而默认情况下,图片下边框与文本对齐。

因此,第一步是将此选项添加baseline=0到您的两个tikzpicture环境中。

不幸的是,在这种情况下这还不够,因为你tikzpicture的 x 轴不是你的图的 x 轴。

我对的内部结构一无所知pgfplot,但如果地块恰好是节点,那么它们的位置也可以进行调整:重新定义节点的锚点可以在垂直放置方面有一定的自由度。

在您的情况下,以下修改通过锚定图的中心原点(编辑)直指(0,0)要点:

\newcommand{\myplotB}[1]{
\begin{tikzpicture}[baseline=0]

(第 13 行)和

\begin{tikzpicture}[baseline=0]
\begin{axis}[anchor=origin,
grid style={blue!50},

(第 31 和 32 行)。

请注意,这仅当 y 轴上的最小值和最大值是对称的时才有效。编辑:不再相关)

完整代码:

\documentclass[]{article}
\usepackage[margin=.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns,angles,quotes,shadings,arrows.meta}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{multicol}
\pgfplotsset{every x tick label/.append style={font=\footnotesize, yshift=0.6ex}}
\pgfplotsset{every y tick label/.append style={font=\footnotesize, xshift=0.5ex}}

\newcommand{\myplotB}[1]{
\begin{tikzpicture}[baseline=0]
\draw[-Triangle] (-2,0)--(2,0);
\draw[Triangle-] (0,2)--(0,-2);
\node[below] at (2,0){$x$};
\node[above] at (0,2){$y$};
\node[below right] at (1,0){\footnotesize{1}};
\draw (0,0) circle [radius=1cm];
\end{tikzpicture}\hspace{.5in}
}

\begin{document}

\section*{Graphing Cosine Functions}
\noindent\rule{15cm}{0.4pt}

The function $y=A\cos t +k$ have \textbf{amplitude} $|A|$ and their \`textbf`{midline} is the horizontal line $y=k$


\begin{tikzpicture}[baseline=0]
\begin{axis}[anchor=origin,
grid style={blue!50},
axis x line = center,
axis y line = center,
xlabel style={above right},
ylabel style={above right},
xlabel={$x$}, ylabel={$y$},
xtick = {-1.5707, 0, ..., 6.28318},
xmin = -2,   xmax =6.28318,
ymin = -3,   ymax = 3,
ytick = {-3,-2,...,3},
xticklabels = {$-\frac{\pi}{2}$, 0, 
    $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$, $2\pi$},
grid  = both,
] at (0,0)
\addplot[samples=300,domain=0:6.28318,color=red] {cos(deg(x))}; 
\filldraw[red] (0,1) circle (3pt) node at (0,1){};
\end{axis}
\end{tikzpicture}
\qquad
\myplotB


\end{document}

答案2

这不是问题的答案,但也许你想实现这样的目标???

\newcounter{angle}
\setcounter{angle}{220}


\begin{tikzpicture}

% Axis
\draw[thick,-stealth,black] (-3,0)--(4,0) coordinate (A) node[below] {$x$}; % x axis
\draw[thick,-stealth,black] (0,-3)--(0,3) node[left] {$y$}; % y axis
\draw[black,thin] (0,0) circle (2.5cm);
\node[black,below] at (2.7,0) {1};
\node[black,above] at (0.2,-3.2) {1};

%\draw[ultra thick,orange] (0,0) -- (\theangle:2.5cm |- 0,0) node[midway,below] {$\cos \alpha$}; % UpOn y axis

\draw (1,0) arc (0:\theangle:1) node at ($(\theangle/2:0.7)$) {$\alpha$};
\draw[dashed, cyan] (\theangle:2.5cm) -- (\theangle:2.5cm |- 0,0) node[sloped, rotate=180, yshift=8pt, midway] {$\sin \alpha$}; % vertical line
\draw[ultra thick,red,rotate=\theangle] (0,0) -- (2.5,0) coordinate (B); 
\foreach \x in {0,30,...,360} {\filldraw[black] (\x:2.5cm) circle(1pt);};
\foreach \x/\xtext in {
        30/\frac{\pi}{6},
        60/\frac{\pi}{3},
        120/\frac{2\pi}{3},
        150/\frac{5\pi}{6},
        210/\frac{7\pi}{6},
        240/\frac{4\pi}{3},
        300/\frac{5\pi}{3},
        330/\frac{11\pi}{6}
        }
    \draw (\x:2.8cm) node {\tiny $\xtext$};
 \foreach \x/\xtext in {
        90/\frac{\pi}{2}}
        \draw (\x:2.7cm) node[xshift=4pt] {\tiny $\xtext$};    
 \foreach \x/\xtext in {
        270/\frac{3\pi}{2}}
        \draw (\x:2.7cm) node[xshift=-5pt] {\tiny $\xtext$};  
 \foreach \x/\xtext in {
        180/\pi,
        360/2\pi}
        \draw (\x:2.7cm) node[yshift=4pt] {\tiny $\xtext$};             

\begin{scope}
\begin{axis}[
    thick,
    y=2.5cm,
    axis lines=center,
    xmin=0, xmax=360,
    ymin=-1, ymax=1,
    anchor=origin, at=(A),
    xshift=3ex,
    enlarge y limits,
    enlarge x limits=upper,
    samples=90,
    xtick={0,30,...,360},
xticklabels={0,
    $\frac{\pi}{6}$,
    $\frac{\pi}{3}$,
    $\frac{\pi}{2}$,        
    $\frac{2\pi}{3}$,
    $\frac{5\pi}{6}$,
    $\pi$,
    $\frac{7\pi}{6}$,
    $\frac{4\pi}{3}$,
    $\frac{3\pi}{2}$,        
    $\frac{5\pi}{3}$,
    $\frac{11\pi}{6}$,
    $2\pi$
    },
    tick label style={font=\tiny},
    ]
    \addplot[domain=0:\theangle,ultra thick, no markers,cyan] {sin(x)} coordinate (C);
    \addplot[domain=\theangle-1:\theangle,ultra thick, no markers,cyan] {sin(x)-sin(x)} coordinate (K);

\end{axis}
\draw [dashed,red, thick] (B) -- (C);
\draw [dashed,cyan, thick] (C) -- (K);
\end{scope}

%\tkzDrawPoints(B);

\end{tikzpicture}

相关内容