tikzpicture 缩放轴后无法居中

tikzpicture 缩放轴后无法居中

使用这个 MWE,我得到了我想要的图,但它没有正确地位于标题上方的中心。我认为问题在于缩放,但这是必要的,因为没有它,图形会太小。

我尝试了各种不同的缩放方法,但它们要么无法正确缩放,要么无法让我将图形置于中心。

我怎样才能使用 将其正确地置于标题的中心\centering

使用不同的值xscale效果更好

图片xscale = 16

在此处输入图片描述


\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,DIV=12]{scrbook}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}

\begin{document}

\begin{figure}[!htpb]
  \centering

\begin{tikzpicture}[yscale=4, xscale = 16]

% Axes
\draw[very thick,latex-latex] (0,1.3) node[left]{$y(t)$}
    |- (0.6,0) node[below]{$t$};
 

% Plot function
\draw[thick,red] (1,0) node[left,black](s0){} -- ++ (0,0) 
    plot[domain=0:0.5,
        samples = 100,
        smooth]({\x}, {1*(1-exp(-(\x/0.1)))});
        
\draw[thick, dashed ,blue] (1,0) node[left,black](s1){}
    -- ++(0,0) 
    plot[domain=0:0.5,
        samples = 100,
        smooth]({\x}, {1});
        
        
\draw[thick, dashed ,black] (1,0) node[left,black](s3){}
    -- ++(0,0) 
    plot[domain=0:0.12,
        samples = 100,
        smooth]({\x}, {\x*10});
        
\end{tikzpicture}

    \caption{Sprungantwort}
    \label{step_resp}
\end{figure}

\end{document}```
 


  


  

答案1

s1、s2、s3处的节点(1,0)放大边界框。我不知道你为什么需要它们:

\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,DIV=12]{scrbook}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}

\begin{document}

\begin{figure}[!htpb]
  \centering

\begin{tikzpicture}[yscale=4, xscale = 16]

% Axes
\draw[very thick,latex-latex] (0,1.3) node[left]{$y(t)$}
    |- (0.6,0) node[below]{$t$};
 

% Plot function
\draw[thick,red] %(1,0) node[left,black](s0){} -- ++ 
    (0,0) 
    plot[domain=0:0.5,
        samples = 20,
        smooth]({\x}, {1*(1-exp(-(\x/0.1)))});
        
\draw[thick, dashed ,blue] %(1,0) node[left,black](s1){} -- ++
    (0,0) 
    plot[domain=0:0.5,
       samples = 20,
        smooth]({\x}, {1});
        
        
\draw[thick, dashed ,black] %(1,0) node[left,black](s3){} -- ++
    (0,0) 
    plot[domain=0:0.12,
        samples = 100,
        smooth]({\x}, {\x*10});
        
\end{tikzpicture}

    \caption{Sprungantwort}
    \label{step_resp}
\end{figure}

\end{document}

在此处输入图片描述

答案2

推杆use as bounding box第一个\draw块修复它,正如所提到的贾斯珀·哈比希特

带修复的 MWE

在此处输入图片描述

\documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,DIV=12]{scrbook}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}

\begin{document}

\begin{figure}[!htpb]
  \centering

\begin{tikzpicture}[yscale=4, xscale = 16]

% Axes
\draw[very thick,latex-latex, use as bounding box] (0,1.3) node[left]{$y(t)$}
    |- (0.6,0) node[below]{$t$};
 

% Plot function
\draw[thick,red] (1,0) node[left,black](s0){} -- ++ (0,0) 
    plot[domain=0:0.5,
        samples = 100,
        smooth]({\x}, {1*(1-exp(-(\x/0.1)))});
        
\draw[thick, dashed ,blue] (1,0) node[left,black](s1){}
    -- ++(0,0) 
    plot[domain=0:0.5,
        samples = 100,
        smooth]({\x}, {1});
        
        
\draw[thick, dashed ,black] (1,0) node[left,black](s3){}
    -- ++(0,0) 
    plot[domain=0:0.12,
        samples = 100,
        smooth]({\x}, {\x*10});
        
\end{tikzpicture}

    \caption{Sprungantwort}
    \label{step_resp}
\end{figure}

\end{document}

相关内容