如果 tikzpicture 尺寸过大,该如何解决?

如果 tikzpicture 尺寸过大,该如何解决?

latex 中的这个 tikzpicture 存在尺寸过大的问题,如何解决这个问题

\documentclass[10pt]{book}
\usepackage[paperheight=9in,paperwidth=7in, top=1in, bottom=0.8in, twocolumn, twoside]{geometry}
\setlength{\columnseprule}{0.4pt}
\usepackage{tikz-cd}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage[centertags]{amsmath}
%\usepackage{amsfonts}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\usepackage{epsfig}
\usepackage{graphicx}\graphicspath{{Graphics/}}
\usepackage{amsthm}
\usepackage{mathptmx}
\usepackage[square,sort&compress]{natbib}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
%\usepackage{mathrsfs}
\usetikzlibrary{arrows}
%\usepackage{amssymb,latexsym}
%\usepackage{amsfonts,amsmath}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
%\usepackage{amsmath,amssymb}
\usepackage{latexsym}
%\usepackage{amsfonts}
\usepackage[arrow,frame,matrix]{xy}
%\usepackage{fixltx2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{booktabs}
\renewcommand{\baselinestretch}{1.5}
\newcommand\aug{\fboxsep=-\fboxrule\!\!\!\fbox{\strut}\!\!\!}
\theoremstyle{definition}
\newtheorem{Thm}{Theorem}[section]
\newtheorem{lem}[Thm]{Lemma}
\newtheorem{pro}[Thm]{Proposition}
\newtheorem{de}[Thm]{Definition}
\newtheorem{re}[Thm]{Remark}
\newtheorem{ex}[Thm]{Example}
\newtheorem{cor}[Thm]{Corollary}
\numberwithin{equation}{section}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{document}
\tableofcontents
\begin{center}
        \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
        \begin{axis}[
        x=0.50cm,y=0.50cm,
        axis lines=middle,
        xmin=-6.1,
        xmax=5.5,
        ymin=-8.8,
        ymax=8.5,
        xtick={-6.0,-5.0,...,5.0},
        ytick={-8.0,-7.0,...,8.0},]
        \clip(-6.1,-8.8) rectangle (5.5,8.5);
        \draw[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] plot(\x,{(\x)^(3.0)});
        \draw (1.3476883107172275,2.1112590651264744) node[anchor=north west] {${\scriptsize (1,1)}$};
        \draw (2.32507514172757,8.906423875548436) node[anchor=north west] {${\scriptsize (2,8)}$};
        \draw (-4.56317490539294,-0.6347321938796605) node[anchor=north west] {${\scriptsize (-1,-1)}$};
        \draw (-5.400935046258949,-7.2437281053859515) node[anchor=north west] {${\scriptsize (-2,-8)}$};
        \begin{scriptsize}
        \draw [fill=black] (0.,0.) circle (2.0pt);
        \draw [fill=black] (1.0000000000003029,1.0000000000009086) circle (2.0pt);
        \draw [fill=black] (2.,8.) circle (2.0pt);
        \draw [fill=black] (-1.,-1.) circle (2.0pt);
        \draw [fill=black] (-2.,-8.) circle (2.0pt);
        \end{scriptsize}
        \end{axis}
        \end{tikzpicture}
    \end{center}
\end{document} 

答案1

这听起来像是 Geogebra,它以输出有争议的 TiZ 代码。通常最好花一些时间来修复它。

使用建议\addplot当然是好的,但也需要重新组织你的序言和 TiZ 代码需要完善。

特别是,指定这么多的十进制数字是没用的,最好使用其他更合理的值来放置标签。

\clip首先要删除的是 Geogebra 添加的指令。

我删除了所有调用多次的包。我还删除了latexsym加载后无用的包amssymb

\aug命令很奇怪而且错误:设置应该\fboxsep是本地的。无论如何,有一种更简单的方法可以获得同样的东西。

由于您正在加载setspace,因此设置行间距的正确方法是使用\setstretch{1.5},而不是重新定义\baselinestretch。如果没有setspace,则更喜欢\linespread{1.5}(但前提是您必须满足愚蠢的教师要求)。

\documentclass[10pt]{book}
\usepackage[paperheight=9in,paperwidth=7in, top=1in, bottom=0.8in, twocolumn, twoside]{geometry}

%\usepackage[utf8]{inputenc} % not needed with recent LaTeX
\usepackage[T1]{fontenc}
%\usepackage{textcomp} % not needed with recent LaTeX

\usepackage[centertags]{amsmath}
\usepackage{amssymb}
\usepackage{tikz-cd}
\usepackage[arrow,frame,matrix]{xy} % both tikz-cd and xy?
\usepackage{amsthm}

\usepackage{mathptmx}
\usepackage{mathrsfs}

\usepackage{graphicx}
\usepackage[square,sort&compress]{natbib}

\usepackage{pgf,tikz,pgfplots}
\usetikzlibrary{arrows}
\pgfplotsset{compat=1.15}

\usepackage{xcolor}

\usepackage{setspace}
\usepackage{booktabs}

\newtheorem{theorem}{Theorem}
\theoremstyle{definition}
\newtheorem{Thm}{Theorem}[section]
\newtheorem{lem}[Thm]{Lemma}
\newtheorem{pro}[Thm]{Proposition}
\newtheorem{de}[Thm]{Definition}
\newtheorem{re}[Thm]{Remark}
\newtheorem{ex}[Thm]{Example}
\newtheorem{cor}[Thm]{Corollary}

\newcommand\aug{\rule[-\dp\strutbox]{2\fboxrule}{\dimexpr\ht\strutbox+\dp\strutbox}}

\definecolor{uuuuuu}{gray}{0.26667}

\graphicspath{{Graphics/}}
\setlength{\columnseprule}{0.4pt}
\setstretch{1.5}
\numberwithin{equation}{section}

\begin{document}

\tableofcontents

\begin{center}
\begin{tikzpicture}
  \begin{axis}[
    x=0.48cm,
    y=0.48cm,
    axis lines=middle,
    xmin=-6.1,
    xmax=5.5,
    ymin=-8.8,
    ymax=8.5,
    xtick={-6.0,-5.0,...,5.0},
    ytick={-8.0,-7.0,...,8.0},
  ]
    \addplot[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] {x^3};
    \draw ( 1.3, 1) node[anchor=west] {$\scriptstyle (1,1)$};
    \draw ( 2.3, 8) node[anchor=west] {$\scriptstyle (2,8)$};
    \draw (-1.3,-1) node[anchor=north east] {$\scriptstyle (-1,-1)$};
    \draw (-2.3,-8) node[anchor=east] {$\scriptstyle (-2,-8)$};
    \draw [fill=black] (0,0) circle (2.0pt);
    \draw [fill=black] (1,1) circle (2.0pt);
    \draw [fill=black] (2,8) circle (2.0pt);
    \draw [fill=black] (-1,-1) circle (2.0pt);
    \draw [fill=black] (-2,-8) circle (2.0pt);
  \end{axis}
\end{tikzpicture}
\end{center}

x\aug x

\end{document} 

由于该图表不太适合该列,我稍微将x和的值降低y到 0.49 厘米,因此过满的箱子警告就消失了。

请仔细检查我的代码与原始代码;例如,\scriptsize在数学模式下无效,但 Geogebra 似乎没有意识到这一点。

在此处输入图片描述

答案2

代替

\draw[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] plot(\x,{(\x)^(3.0)});

\addplot[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] {x^3};

替换后的完整示例:

\documentclass[10pt]{book}
\usepackage[paperheight=9in,paperwidth=7in, top=1in, bottom=0.8in, twocolumn, twoside]{geometry}
\setlength{\columnseprule}{0.4pt}
\usepackage{tikz-cd}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage[centertags]{amsmath}
%\usepackage{amsfonts}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\usepackage{epsfig}
\usepackage{graphicx}\graphicspath{{Graphics/}}
\usepackage{amsthm}
\usepackage{mathptmx}
\usepackage[square,sort&compress]{natbib}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
%\usepackage{mathrsfs}
\usetikzlibrary{arrows}
%\usepackage{amssymb,latexsym}
%\usepackage{amsfonts,amsmath}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
%\usepackage{amsmath,amssymb}
\usepackage{latexsym}
%\usepackage{amsfonts}
\usepackage[arrow,frame,matrix]{xy}
%\usepackage{fixltx2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{booktabs}
\renewcommand{\baselinestretch}{1.5}
\newcommand\aug{\fboxsep=-\fboxrule\!\!\!\fbox{\strut}\!\!\!}
\theoremstyle{definition}
\newtheorem{Thm}{Theorem}[section]
\newtheorem{lem}[Thm]{Lemma}
\newtheorem{pro}[Thm]{Proposition}
\newtheorem{de}[Thm]{Definition}
\newtheorem{re}[Thm]{Remark}
\newtheorem{ex}[Thm]{Example}
\newtheorem{cor}[Thm]{Corollary}
\numberwithin{equation}{section}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{document}
\tableofcontents
\begin{center}
        \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
        \begin{axis}[
        x=0.50cm,y=0.50cm,
        axis lines=middle,
        xmin=-6.1,
        xmax=5.5,
        ymin=-8.8,
        ymax=8.5,
        xtick={-6.0,-5.0,...,5.0},
        ytick={-8.0,-7.0,...,8.0},]
        \clip(-6.1,-8.8) rectangle (5.5,8.5);
%        \draw[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] plot(\x,{(\x)^(3.0)});
        \addplot[line width=1.0pt,smooth,samples=100,domain=-6.1:5.5] {x^3};
        \draw (1.3476883107172275,2.1112590651264744) node[anchor=north west] {${\scriptsize (1,1)}$};
        \draw (2.32507514172757,8.906423875548436) node[anchor=north west] {${\scriptsize (2,8)}$};
        \draw (-4.56317490539294,-0.6347321938796605) node[anchor=north west] {${\scriptsize (-1,-1)}$};
        \draw (-5.400935046258949,-7.2437281053859515) node[anchor=north west] {${\scriptsize (-2,-8)}$};
        \begin{scriptsize}
        \draw [fill=black] (0.,0.) circle (2.0pt);
        \draw [fill=black] (1.0000000000003029,1.0000000000009086) circle (2.0pt);
        \draw [fill=black] (2.,8.) circle (2.0pt);
        \draw [fill=black] (-1.,-1.) circle (2.0pt);
        \draw [fill=black] (-2.,-8.) circle (2.0pt);
        \end{scriptsize}
        \end{axis}
        \end{tikzpicture}
    \end{center}
\end{document}

答案3

再举一个例子,如何绘制图表:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
    dot/.style = {circle, fill, inner sep=1.5pt},
    every label/.append style = {font=\scriptsize},
    every pin/.append style = {pin distance=4mm, inner sep=0pt, font=\scriptsize}
                        ]
\begin{axis}[
axis lines = middle,
xmin=-4.5,  xmax=3.5,
ymin=-8.5,  ymax=8.5,
xtick = {-4,-3,...,3},
xticklabels = {$-4$,$-3$,$-2$,,1,...,4},
ytick={-8,-7,...,8},
tick label style = {font=\scriptsize}
            ]
\addplot[line width=1pt, samples=100,domain=-4.1:4] {x^3};
\node[dot, label=right:{$( 1, 1)$}] at ( 1, 1) {};
\node[dot, label=right:{$( 2, 8)$}] at ( 2, 8) {};
\node[dot, pin={[yshift=3mm]below left:$(-1,-1)$}] at (-1,-1) {};
\node[dot, label=left:{$(-2,-8)$}] at (-2,-8) {};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容